Changeset View
Changeset View
Standalone View
Standalone View
src/unit/engine/NoseTestEngine.php
<?php | <?php | ||||
/** | /** | ||||
* Very basic 'nose' unit test engine wrapper. | * Very basic 'nose' unit test engine wrapper. | ||||
* | * | ||||
* Requires nose 1.1.3 for code coverage. | * Requires nose 1.1.3 and python-coverage 3.6 for code coverage. | ||||
*/ | */ | ||||
final class NoseTestEngine extends ArcanistUnitTestEngine { | final class NoseTestEngine extends ArcanistUnitTestEngine { | ||||
private $sourcePath = './'; | |||||
public function run() { | public function run() { | ||||
if ($this->getPaths()) { | |||||
return $this->runAutoGuessTests(); | |||||
} | |||||
$paths = $this->getPathsMap(); | |||||
$test_paths = array_unique($paths); | |||||
return $this->runTests($test_paths, $this->sourcePath); | |||||
} | |||||
private function runAutoGuessTests() { // Possibly not used by anyone anywhere. | |||||
$paths = $this->getPaths(); | $paths = $this->getPaths(); | ||||
$affected_tests = array(); | $affected_tests = array(); | ||||
foreach ($paths as $path) { | foreach ($paths as $path) { | ||||
$absolute_path = Filesystem::resolvePath($path); | $absolute_path = Filesystem::resolvePath($path); | ||||
if (is_dir($absolute_path)) { | if (is_dir($absolute_path)) { | ||||
$absolute_test_path = Filesystem::resolvePath('tests/'.$path); | $absolute_test_path = Filesystem::resolvePath('tests/'.$path); | ||||
▲ Show 20 Lines • Show All 91 Lines • ▼ Show 20 Lines | final class NoseTestEngine extends ArcanistUnitTestEngine { | ||||
} | } | ||||
public function readCoverage($cover_file, $source_path) { | public function readCoverage($cover_file, $source_path) { | ||||
$coverage_dom = new DOMDocument(); | $coverage_dom = new DOMDocument(); | ||||
$coverage_dom->loadXML(Filesystem::readFile($cover_file)); | $coverage_dom->loadXML(Filesystem::readFile($cover_file)); | ||||
$reports = array(); | $reports = array(); | ||||
$classes = $coverage_dom->getElementsByTagName('class'); | $classes = $coverage_dom->getElementsByTagName('class'); | ||||
foreach ($classes as $class) { | foreach ($classes as $class) { | ||||
$path = $class->getAttribute('filename'); | $path = $class->getAttribute('filename'); | ||||
$root = $this->getWorkingCopy()->getProjectRoot(); | $root = $this->getWorkingCopy()->getProjectRoot(); | ||||
if (!Filesystem::isDescendant($path, $root)) { | if (!Filesystem::isDescendant($path, $root)) { | ||||
continue; | continue; | ||||
} | } | ||||
Show All 27 Lines | foreach ($classes as $class) { | ||||
} | } | ||||
$reports[$path] = $coverage; | $reports[$path] = $coverage; | ||||
} | } | ||||
return $reports; | return $reports; | ||||
} | } | ||||
public function getEngineConfigurationName() { | |||||
return 'pynose'; | |||||
} | |||||
public function setUnitConfigurationValue($key, $value) { | |||||
switch ($key) { | |||||
case 'source_path': | |||||
$this->sourcePath = $value; | |||||
return; | |||||
} | |||||
return parent::setUnitConfigurationValue($key, $value); | |||||
} | |||||
public function getEngineConfigurationOptions() { | |||||
return array( | |||||
'source_path' => array( | |||||
'type' => 'optional string', | |||||
'help' => 'Root of source code. Defaults to repository\'s root.', | |||||
), | |||||
); | |||||
} | |||||
} | } |