From 0476bf8f4af238849f1cb0e27d6b8f9edc587881 Mon Sep 17 00:00:00 2001 From: Aviv Eyal Date: Tue, 14 May 2013 06:38:22 -0700 Subject: [PATCH] more reusable nosetest engine Summary: The NoseTestEngine class has some usefull code for parsing nosetest, but it assumes a very specific code/test layout. I've pulled this logic abit apart, which lets me reuse the nose-related parts with my existing project layout, by having my custom engine just call runTests() with the relevant paths. Test Plan: Run on a customized project with coverage, see coverage results. Reviewers: epriestley, roman.barzyczak Reviewed By: epriestley CC: seporaitis, aran, Korvin, zeeg Differential Revision: https://secure.phabricator.com/D5921 --- src/unit/engine/NoseTestEngine.php | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/unit/engine/NoseTestEngine.php b/src/unit/engine/NoseTestEngine.php index 352cd346..49f03994 100644 --- a/src/unit/engine/NoseTestEngine.php +++ b/src/unit/engine/NoseTestEngine.php @@ -38,13 +38,17 @@ final class NoseTestEngine extends ArcanistBaseUnitTestEngine { } } - if (empty($affected_tests)) { + return $this->runTests($affected_tests, './'); + } + + public function runTests($test_paths, $source_path) { + if (empty($test_paths)) { return array(); } $futures = array(); $tmpfiles = array(); - foreach ($affected_tests as $test_path) { + foreach ($test_paths as $test_path) { $xunit_tmp = new TempFile(); $cover_tmp = new TempFile(); @@ -73,7 +77,7 @@ final class NoseTestEngine extends ArcanistBaseUnitTestEngine { $xunit_tmp = $tmpfiles[$test_path]['xunit']; $cover_tmp = $tmpfiles[$test_path]['cover']; - $results[] = $this->parseTestResults($test_path, + $results[] = $this->parseTestResults($source_path, $xunit_tmp, $cover_tmp); } @@ -94,7 +98,7 @@ final class NoseTestEngine extends ArcanistBaseUnitTestEngine { return new ExecFuture("%C %s", $cmd_line, $path); } - public function parseTestResults($path, $xunit_tmp, $cover_tmp) { + public function parseTestResults($source_path, $xunit_tmp, $cover_tmp) { // xunit xsd: https://gist.github.com/959290 $xunit_dom = new DOMDocument(); $xunit_dom->loadXML(Filesystem::readFile($xunit_tmp)); @@ -102,7 +106,7 @@ final class NoseTestEngine extends ArcanistBaseUnitTestEngine { // coverage is for all testcases in the executed $path $coverage = array(); if ($this->getEnableCoverage() !== false) { - $coverage = $this->readCoverage($cover_tmp); + $coverage = $this->readCoverage($cover_tmp, $source_path); } $results = array(); @@ -168,9 +172,9 @@ final class NoseTestEngine extends ArcanistBaseUnitTestEngine { return $results; } - public function readCoverage($path) { + public function readCoverage($cover_file, $source_path) { $coverage_dom = new DOMDocument(); - $coverage_dom->loadXML(Filesystem::readFile($path)); + $coverage_dom->loadXML(Filesystem::readFile($cover_file)); $reports = array(); $classes = $coverage_dom->getElementsByTagName("class"); @@ -180,7 +184,7 @@ final class NoseTestEngine extends ArcanistBaseUnitTestEngine { // e.g.: tornado.web.py $relative_path = explode(".", $class->getAttribute("filename")); array_pop($relative_path); - $relative_path = implode("/", $relative_path); + $relative_path = $source_path .'/'. implode("/", $relative_path); // first we check if the path is a directory (a Python package), if it is // set relative and absolute paths to have __init__.py at the end.