def test_current_call(self): self.mock.foo('one two three') self.mock.foo(foo='bar') with assert_not_raises(): with assert_mock(self.mock) as m: assert current_call(m).name == 'foo' assert 'two' in current_call(m).args[0] skip(m, 1) assert current_call(m).kwargs['foo'] == 'bar'
def test_current_call_with_single_arg(self): self.mock.foo('bar') with assert_not_raises(): with assert_mock(self.mock) as m: with current_call(m) as c: c.arg == 'bar' self.mock.reset_mock() self.mock.foo('bar', 'baz') with assert_raises(AssertionError) as cm: with assert_mock(self.mock) as m: with current_call(m) as c: c.arg assert cm.exception.args == ("Call should only have a single argument", )
def test_current_call_as_contextmanager(self): self.mock.foo('one two three') self.mock.foo(foo='bar') with assert_not_raises(): with assert_mock(self.mock) as m: with current_call(m) as c: c.name == 'foo' assert 'two' in c.args[0] # No need to `skip(m, 1)` as above. with current_call(m) as c: assert c.kwargs['foo'] == 'bar' no_more_calls(m)
def test_context_dependent_help(self): computes = db.get_root()['oms_root']['computes'] cid = computes.add(self.make_compute()) transaction.commit() self.terminal.reset_mock() self._cmd('set computes/%s -h' % cid) with assert_mock(self.terminal) as t: assert 'hostname=' in current_call(t).arg
def test_complete_consumed_switches(self): self._tab_after('ls --help') with assert_mock(self.terminal) as t: t.write(' ') no_more_calls(t) self._tab_after('-') with assert_mock(self.terminal) as t: skip(t, 2) with current_call(t) as c: assert 'help' not in c.arg assert '-h' not in c.arg
def test_last_error(self): class meta(FakeModule): class FailingCommand(Cmd): command('fail') def execute(self, args): raise Exception('some mock error') grok('martiantest.fake.meta') self._cmd('fail') self.terminal.reset_mock() self._cmd('last_error') with assert_mock(self.terminal) as t: assert 'some mock error' in current_call(t).arg, 'Apparently, fail command did not fail'
def test_last_error(self): class meta(FakeModule): class FailingCommand(Cmd): command('fail') def execute(self, args): raise Exception('some mock error') grok('martiantest.fake.meta') self._cmd('fail') self.terminal.reset_mock() self._cmd('last_error') with assert_mock(self.terminal) as t: assert 'some mock error' in current_call( t).arg, 'Apparently, fail command did not fail'
def test_help(self): self._cmd('help') with assert_mock(self.terminal) as t: for cmd in commands().keys(): assert cmd in current_call(t).arg