コード例 #1
0
 def test_gather_constructs__ifexp_simple_decision(self):
     def test_module():
         a = 3
         b = 0 if a == 4 else 1
     module, source = load_module(test_module)
     pragmas = self._get_pragmas(source)
     
     metadata = self._make_one().analyze(DummyConfig(), 'modname', module, pragmas)
     assert "2.1" in metadata.constructs, metadata.constructs
     decision = metadata.constructs["2.1"]
     assert isinstance(decision, constructs.BooleanDecision)
コード例 #2
0
 def test_gather_lines__with_pragmas(self):
     def test_module():
         a = 3
         if a == 4: 
             b = 0 # pragma: no cover
         else:
             b = 1
     module, source = load_module(test_module)
     pragmas = self._get_pragmas(source)
     
     metadata = self._make_one().analyze(DummyConfig(), 'modname', module, pragmas)
     assert set([1, 2, 5]) == set(metadata.lines), set(metadata.lines)
コード例 #3
0
 def test_visit_Assert(self):
     def test_module():
         assert a or b
     module, source = load_module(test_module)
     pragmas = self._get_pragmas(source)
     
     metadata = self._make_one().analyze(DummyConfig(), 'modname', module, pragmas)
     assert 2 == len(metadata.constructs)
     decision = metadata.constructs["1.1"]
     assert isinstance(decision, constructs.BooleanDecision)
     boolop = metadata.constructs["1.2"]
     assert isinstance(boolop, constructs.LogicalOr)
コード例 #4
0
 def test_visit_Or_unreachable_False(self):
     def test_module():
         c =  a or True
     module, source = load_module(test_module)
     pragmas = self._get_pragmas(source)
     
     metadata = self._make_one().analyze(DummyConfig(), 'modname', module, pragmas)
     assert 2 == len(metadata.constructs), len(metadata.constructs)
     decision = metadata.constructs["1.1"]
     assert list(decision.conditions[False])[0] == constructs.UnreachableCondition
     assert isinstance(decision, constructs.BooleanDecision)
     boolop = metadata.constructs["1.2"]
     assert isinstance(boolop, constructs.LogicalOr)
コード例 #5
0
 def _load_and_compile_module(self, module_func):
     module, source = load_module(module_func)
     from instrumental.pragmas import PragmaFinder
     pragmas = PragmaFinder().find_pragmas(source)
     from instrumental.metadata import MetadataGatheringVisitor
     config = DummyConfig()
     self.recorder.add_metadata(
         MetadataGatheringVisitor.analyze(config, module_func.__name__,
                                          source, pragmas))
     # self.recorder.add_source(module_func.__name__, source)
     transformer = CoverageAnnotator(config, module_func.__name__,
                                     self.recorder)
     inst_module = transformer.visit(module)
     sys.stdout.write(renderer.render(inst_module) + "\n")
     code = compile(inst_module, '<string>', 'exec')
     return code
コード例 #6
0
 def test_gather_constructs__multiple_ifexps(self):
     def test_module():
         a = 3
         b, c = 0 if a == 4 else 1, 2 if a == 2 or a == 3 else 3
     module, source = load_module(test_module)
     pragmas = self._get_pragmas(source)
     
     metadata = self._make_one().analyze(DummyConfig(), 'modname', module, pragmas)
     assert 6 == len(metadata.constructs), metadata.constructs
     decision = metadata.constructs["2.1"]
     assert isinstance(decision, constructs.BooleanDecision)
     comparison = metadata.constructs["2.2"]
     assert isinstance(comparison, constructs.Comparison)
     decision = metadata.constructs["2.3"]
     assert isinstance(decision, constructs.BooleanDecision)
     decision = metadata.constructs["2.4"]
     assert isinstance(decision, constructs.LogicalOr)
     comparison = metadata.constructs["2.5"]
     assert isinstance(comparison, constructs.Comparison)
     comparison = metadata.constructs["2.6"]
     assert isinstance(comparison, constructs.Comparison)