示例#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()