]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Fix unit test coverage for `NoseTestEngine`.
authorJoshua Spence <josh@joshuaspence.com>
Fri, 7 Mar 2014 18:16:27 +0000 (10:16 -0800)
committerepriestley <git@epriestley.com>
Fri, 7 Mar 2014 18:17:04 +0000 (10:17 -0800)
Summary:
I noticed that code coverage wasn't showing in Differential for
some repositories that we are using with Phabricator.

`arc unit` would should unit test coverage, but the paths were messy
(for example, `.//foo/bar.py` instead of `foo/bar.py`). As a result,
the code coverage info wasn't recognised as being for the correct
module.

I'm not sure why this logic is the way that it is... perhaps this is to
do with an older version of `nose` (I am using v1.3.0).

Test Plan:
I created a diff for an internal repository that we have, and
observed that code coverage was displayed in Differential.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley

CC: Korvin, epriestley, aran, seporaitis, avive, dctrwatson, zeeg
Differential Revision: https://secure.phabricator.com/D8433

src/unit/engine/NoseTestEngine.php

index 807e4161daa6cb0d395b79935ea2cdf40c7f3639..dc7087f45f53158003fde3b673116645980532a2 100644 (file)
@@ -122,35 +122,15 @@ final class NoseTestEngine extends ArcanistBaseUnitTestEngine {
     $classes = $coverage_dom->getElementsByTagName("class");
 
     foreach ($classes as $class) {
-      // filename is actually python module path with ".py" at the end,
-      // e.g.: tornado.web.py
-      $relative_path = explode(".", $class->getAttribute("filename"));
-      array_pop($relative_path);
-      $relative_path = $source_path .'/'. implode("/", $relative_path);
-      $relative_path = Filesystem::readablePath($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.
-      $absolute_path = Filesystem::resolvePath($relative_path);
-      if (is_dir($absolute_path)) {
-        $relative_path .= "/__init__.py";
-        $absolute_path .= "/__init__.py";
-      }
-
-      // then we check if the path with ".py" at the end is file (a Python
-      // submodule), if it is - set relative and absolute paths to have
-      // ".py" at the end.
-      if (is_file($absolute_path.".py")) {
-        $relative_path .= ".py";
-        $absolute_path .= ".py";
-      }
+      $path = $class->getAttribute("filename");
+      $root = $this->getWorkingCopy()->getProjectRoot();
 
-      if (!file_exists($absolute_path)) {
+      if (!Filesystem::isDescendant($path, $root)) {
         continue;
       }
 
       // get total line count in file
-      $line_count = count(file($absolute_path));
+      $line_count = count(phutil_split_lines(Filesystem::readFile($path)));
 
       $coverage = "";
       $start_line = 1;
@@ -178,7 +158,7 @@ final class NoseTestEngine extends ArcanistBaseUnitTestEngine {
         }
       }
 
-      $reports[$relative_path] = $coverage;
+      $reports[$path] = $coverage;
     }
 
     return $reports;