]> khamidou — GitHub mirrors - arcanist.git/commitdiff
more reusable nosetest engine
authorAviv Eyal <c-aeyal@groupon.com>
Tue, 14 May 2013 13:38:22 +0000 (06:38 -0700)
committerepriestley <git@epriestley.com>
Tue, 14 May 2013 13:38:22 +0000 (06:38 -0700)
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

index 352cd346337f6f64daf86988043d50d2a91d986c..49f03994d07be28ba7fc28da5aeb2ff9581be41f 100644 (file)
@@ -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.