Changeset 23

Show
Ignore:
Timestamp:
05/29/06 13:12:38 (7 years ago)
Author:
mk
Message:

Fixed is_test_file() function.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/mk/cheesecake/cheesecake_index.py

    r22 r23  
    3333 
    3434default_temp_directory = os.path.join(tempfile.gettempdir(), 'cheesecake_sandbox') 
     35 
     36 
     37def has_extension(filename, ext): 
     38    return os.path.splitext(filename)[1] == ext 
    3539 
    3640 
     
    604608        for rootdir, dirs, files in os.walk(self.package_name): 
    605609            head, tail = os.path.split(rootdir) 
    606             dirs_in_rootdir = rootdir.split(os.path.sep) 
     610 
     611            # Don't take package name into account when checking 
     612            # directories' names. 
     613            dirs_in_rootdir = rootdir.split(os.path.sep)[1:] 
     614 
    607615            for cheese_dir in self.cheese_dirs: 
    608616                if re.search("^%s" % cheese_dir, tail): 
     
    645653                    self.docstring_cnt += code.docstring_count() 
    646654                    self.functions += code.functions 
    647  
    648                 if os.path.splitext(file)[1] == ".pyc": 
     655                elif self.is_test_file(file, dirs_in_rootdir): 
     656                    self.pkg_files["test"].append(fullpath) 
     657                    self.log.debug("test file found: " + fullpath) 
     658                elif self.is_pyc_file(file, dirs_in_rootdir): 
    649659                    self.pkg_files["pyc"].append(fullpath) 
    650660                    self.log.debug("pyc file found: " + fullpath) 
    651  
    652                 if self.is_test_file(file, dirs_in_rootdir): 
    653                     self.pkg_files["test"].append(fullpath) 
    654                     self.log.debug("test file found: " + fullpath) 
    655661 
    656662        len_pyc_list = len(self.pkg_files["pyc"]) 
     
    664670        os.chdir(cwd) 
    665671 
     672    def is_pyc_file(self, filename, dirs): 
     673        return has_extension(file, ".pyc") 
     674 
    666675    def is_py_file(self, file, dirs): 
    667676        """ 
     
    669678        in special directory 
    670679        """ 
    671         if os.path.splitext(file)[1] != ".py"
     680        if not has_extension(file, ".py")
    672681            return False 
    673682        if file in ["setup.py", "ez_setup.py", "__init__.py", "__pkginfo__.py"]: 
     
    681690        return True 
    682691 
    683     def is_test_file(self, file, dirs): 
     692    def is_test_file(self, filename, dirs): 
    684693        """ 
    685694        Return True is file is in directory rooted at "test" or "tests" 
    686695        """ 
    687         if not file.endswith(".py"): 
     696        if not has_extension(filename, ".py"): 
    688697            return False 
    689698        if file in ["__init__.py"]: