Exemplo n.º 1
0
class StatJavaMeanCcnTests(TestCase):
    def setUp(self):
        self.ccn_file_creator = CcnFileCreator()

    def test_proper_ccn_is_found_in_single_file(self):
        directory = mkdtemp("-caboose-java-ccn-single-test")
        self.ccn_file_creator.create_file_with_ccn(3, directory)

        fp = FilePackage()
        fp.add_directory(directory)
        file_iterator = FileIterator([fp])
        
        stat = StatJavaMeanCcn()
        stat.set_files(file_iterator.files())
        eq_(3, stat.get_stat())
        rmtree(directory)

    def test_proper_ccn_is_found_in_multiple_files(self):
        directory = mkdtemp("-caboose-java-ccn-multiple-test")
        self.ccn_file_creator.create_file_with_ccn(2, directory)
        self.ccn_file_creator.create_file_with_ccn(8, directory)

        fp = FilePackage()
        fp.add_directory(directory)
        file_iterator = FileIterator([fp])

        stat = StatJavaMeanCcn()
        stat.set_files(file_iterator.files())
        eq_(5, stat.get_stat())
        rmtree(directory)

    def test_proper_ccn_is_found_in_multiple_files_float(self):
        directory = mkdtemp("-caboose-java-ccn-multiple-float-test")
        self.ccn_file_creator.create_file_with_ccn(3, directory)
        self.ccn_file_creator.create_file_with_ccn(8, directory)

        fp = FilePackage()
        fp.add_directory(directory)
        file_iterator = FileIterator([fp])

        stat = StatJavaMeanCcn()
        stat.set_files(file_iterator.files())
        eq_(5.5, stat.get_stat())
        rmtree(directory)
    
    def test_stat_lines_counts_zero_if_directory_does_not_exist(self):
        directory = mkdtemp("-caboose-ccn-non-exist-dir-test")
        inner = path.join(directory, 'nonexistant')

        fp = FilePackage()
        fp.add_directory(inner)
        file_iterator = FileIterator([fp])

        stat = StatJavaMeanCcn()
        stat.set_files(file_iterator.files())
        eq_(0, stat.get_stat())
        rmtree(directory)
    
    def test_stat_has_right_name(self):
        eq_(StatJavaMeanCcn.get_name(), "java_mean_ccn")
class StatJavaMeanCcnTests(TestCase):
    def setUp(self):
        self.ccn_file_creator = CcnFileCreator()

    def test_zero_ccn_func_count_when_limit_not_met(self):
        directory = mkdtemp("-caboose-java-ccn-count-low-single-test")
        self.ccn_file_creator.create_file_with_ccn(1, directory)

        fp = FilePackage()
        fp.add_directory(directory)
        file_iterator = FileIterator([fp])
        
        stat = StatJavaCcnFuncCount()
        stat.set_ccn_limit(2)
        stat.set_files(file_iterator.files())
        eq_(0, stat.get_stat())
        rmtree(directory)

    def test_ccn_func_count_when_over_limit_single(self):
        directory = mkdtemp("-caboose-java-ccn-count-high-single-test")
        self.ccn_file_creator.create_file_with_ccn(5, directory)

        fp = FilePackage()
        fp.add_directory(directory)
        file_iterator = FileIterator([fp])
        
        stat = StatJavaCcnFuncCount()
        stat.set_ccn_limit(2)
        stat.set_files(file_iterator.files())
        eq_(1, stat.get_stat())
        rmtree(directory)

    def test_ccn_func_count_when_over_limit_multiple(self):
        directory = mkdtemp("-caboose-java-ccn-count-high-single-test")
        self.ccn_file_creator.create_file_with_funcs_with_ccns(directory, [5, 1, 3, 2])

        fp = FilePackage()
        fp.add_directory(directory)
        file_iterator = FileIterator([fp])
        
        stat = StatJavaCcnFuncCount()
        stat.set_ccn_limit(3)
        stat.set_files(file_iterator.files())
        eq_(2, stat.get_stat())
        rmtree(directory)

    def test_stat_has_right_name(self):
        eq_(StatJavaCcnFuncCount.get_name(), "java_ccn_func_count")
Exemplo n.º 3
0
 def setUp(self):
     self.ccn_file_creator = CcnFileCreator()