コード例 #1
0
 def setup_mocks(self, modules):
     self.mocked_modules = {}
     self.modules = {}
     # MatPlotLib's PyPlot
     fake_module = types.ModuleType('matplotlib')
     fake_module.pyplot = types.ModuleType('pyplot')
     self.mocked_modules['matplotlib'] = fake_module
     self.mocked_modules['matplotlib.pyplot'] = fake_module.pyplot
     mock_plt = mocked.MockPlt()
     mock_plt._add_to_module(fake_module.pyplot)
     self.modules['matplotlib.pyplot'] = mock_plt
コード例 #2
0
 def _add_mock(self, module_name, module_data):
     # MatPlotLib's PyPlot
     if module_name == 'matplotlib':
         matplotlib, modules = mocked.create_module('matplotlib.pyplot')
         self.mocked_modules.update(modules)
         if module_data is True:
             mock_plt = mocked.MockPlt()
             mock_plt._add_to_module(matplotlib.pyplot)
             self.modules['matplotlib.pyplot'] = mock_plt
         else:
             module_data._add_to_module(matplotlib.pyplot)
     else:
         root, modules = mocked.create_module(module_name)
         self.mocked_modules.update(modules)
         self.modules[module_name] = module_data
         module_data._add_to_module(root)
コード例 #3
0
 def reset_default_overrides(self):
     """
     Resets the list of blocked functions and modules to its starting
     state. This blocks ``compile``, ``eval``, ``exec``, ``globals``,
     and provides mocked versions of ``open`` and ``import`` that are
     more restricted. It also blocks the ``pedal`` module.
     """
     self._module_overrides['__builtins__'] = {}
     self.block_function('compile')
     self.block_function('eval')
     self.block_function('exec')
     self.block_function('globals')
     self.mock_function('open', mocked._restricted_open)
     self.mock_function('__import__', mocked._restricted_import)
     # TODO: This breaks coverage for some reason; it's a builtin?
     self.block_module('pedal')
     self.mock_module('turtle', mocked.MockTurtle(), 'turtles')
     self.mock_module('matplotlib.pyplot', mocked.MockPlt(), 'plotting')