def mock_command_line(self, args, options=None): """Run `args` through the command line, with a Mock. `options` is a dict of names and values to pass to `set_option`. Returns the Mock it used and the status code returned. """ mk = self.model_object() if options is not None: for name, value in options.items(): mk.config.set_option(name, value) patchers = [ mock.patch("coverage.cmdline." + name, getattr(mk, name)) for name in self.MOCK_GLOBALS ] for patcher in patchers: patcher.start() try: ret = command_line(args) finally: for patcher in patchers: patcher.stop() return mk, ret
def test_fail_under(results, fail_under, cmd, ret): cov = CoverageReportingFake(*results) if fail_under is not None: cov.set_option("report:fail_under", fail_under) with mock.patch("coverage.cmdline.Coverage", lambda *a,**kw: cov): ret_actual = command_line(cmd) assert ret_actual == ret
def test_fail_under(results, fail_under, cmd, ret): cov = CoverageReportingFake(*results) if fail_under is not None: cov.set_option("report:fail_under", fail_under) with mock.patch("coverage.cmdline.Coverage", lambda *a, **kw: cov): ret_actual = command_line(cmd) assert ret_actual == ret
def mock_command_line(self, args, options=None): """Run `args` through the command line, with a Mock. `options` is a dict of names and values to pass to `set_option`. Returns the Mock it used and the status code returned. """ mk = self.model_object() if options is not None: for name, value in options.items(): mk.config.set_option(name, value) patchers = [ mock.patch("coverage.cmdline."+name, getattr(mk, name)) for name in self.MOCK_GLOBALS ] for patcher in patchers: patcher.start() try: ret = command_line(args) finally: for patcher in patchers: patcher.stop() return mk, ret
def mock_command_line(self, args): """Run `args` through the command line, with a Mock. Returns the Mock it used and the status code returned. """ m = self.model_object() ret = command_line( args, _covpkg=m, _run_python_file=m.run_python_file, _run_python_module=m.run_python_module, _help_fn=m.help_fn, ) return m, ret
def mock_command_line(self, args, path_exists=None): """Run `args` through the command line, with a Mock. Returns the Mock it used and the status code returned. """ m = self.model_object() m.path_exists.return_value = path_exists ret = command_line( args, _covpkg=m, _run_python_file=m.run_python_file, _run_python_module=m.run_python_module, _help_fn=m.help_fn, _path_exists=m.path_exists, ) return m, ret
def mock_command_line(self, args, options=None): """Run `args` through the command line, with a Mock. `options` is a dict of names and values to pass to `set_option`. Returns the Mock it used and the status code returned. """ m = self.model_object() for name, value in (options or {}).items(): m.set_option(name, value) ret = command_line( args, _covpkg=m, _run_python_file=m.run_python_file, _run_python_module=m.run_python_module, _help_fn=m.help_fn, ) return m, ret
def test_fail_under(results, fail_under, cmd, ret): cov = CoverageReportingFake(*results) if fail_under is not None: cov.set_option("report:fail_under", fail_under) ret_actual = command_line(cmd, _covpkg=cov) assert ret_actual == ret