예제 #1
0
    def test_load_package(self):
        from instrumental.instrument import AnnotatorFactory
        from instrumental.metadata import MetadataGatheringVisitor
        from instrumental.monkey import load_module_factory
        from instrumental.pragmas import PragmaFinder
        from instrumental.recorder import ExecutionRecorder

        import instrumental.test.samples
        samples_directory = os.path.dirname(instrumental.test.samples.__file__)
        simple_name = 'instrumental.test.samples.package'
        simple_path = os.path.join(samples_directory, 'package')

        source = open(os.path.join(simple_path, '__init__.py'), "r").read()
        pragmas = PragmaFinder().find_pragmas(source)
        metadata = MetadataGatheringVisitor.analyze(self.config, simple_name,
                                                    source, pragmas)

        recorder = ExecutionRecorder.get()
        recorder.add_metadata(metadata)
        visitor_factory = AnnotatorFactory(self.config, recorder)
        load_module = load_module_factory(
            ['instrumental.test.samples.package'], [], visitor_factory)

        load_module(simple_name, None, simple_path,
                    (None, None, imp.PKG_DIRECTORY))

        assert simple_name in sys.modules
예제 #2
0
 def test_construct_with_literal(self):
     recorder = ExecutionRecorder.get()
     node = ast.BoolOp(op=ast.Or(),
                       values=[ast.Name(id="foo"),
                               ast.Str(s='""')],
                       lineno=1,
                       col_offset=0)
     recorder.add_BoolOp('somemodule', '1.1', node, [], None)
예제 #3
0
 def test_add_a_non_BoolOp(self):
     recorder = ExecutionRecorder.get()
     node = ast.BoolOp(op=4,
                       values=[ast.Name(id="foo"),
                               ast.Str(s='""')],
                       lineno=1,
                       col_offset=0)
     try:
         recorder.add_BoolOp('somemodule', node, [], None)
     except TypeError as exc:
         assert "BoolOp" in str(exc), exc
예제 #4
0
    def test_load_non_target_module(self):
        from instrumental.instrument import AnnotatorFactory
        from instrumental.monkey import load_module_factory
        from instrumental.recorder import ExecutionRecorder

        recorder = ExecutionRecorder.get()
        visitor_factory = AnnotatorFactory(self.config, recorder)
        load_module = load_module_factory([], [], visitor_factory)

        import instrumental.test.samples
        samples_directory = os.path.dirname(instrumental.test.samples.__file__)
        simple_name = 'instrumental.test.samples.simple'
        simple_path = os.path.join(samples_directory, 'simple.py')
        simple_fh = open(simple_path, 'r')
        load_module(simple_name, simple_fh, simple_path,
                    ('.py', 'r', imp.PY_SOURCE))

        assert simple_name in sys.modules
예제 #5
0
 def recorder(self):
     return ExecutionRecorder.get()
예제 #6
0
 def teardown(self):
     ExecutionRecorder.get().stop()
예제 #7
0
 def setup(self):
     self.config = DummyConfig()
     ExecutionRecorder.reset()
     ExecutionRecorder.get().start()
예제 #8
0
def __setup_recorder():  # pragma: no cover
    from instrumental.recorder import ExecutionRecorder
    _xxx_recorder_xxx_ = ExecutionRecorder.get()
예제 #9
0
 def setup(self):
     # First clear out the recorder so that we'll create a new one
     ExecutionRecorder.reset()
     self.recorder = ExecutionRecorder.get()
     self.recorder.start()
예제 #10
0
 def setup(self):
     # First clear out the recorder so that we'll create a new one
     ExecutionRecorder.reset()
     self.recorder = ExecutionRecorder.get()
     self.config = DummyConfig()