def test_cat_folders(self): for folder in self.tlds: self._cmd('cat %s' % folder) with assert_mock(self.terminal) as t: skip(t, 1) skip(t, 1) t.write("user@oms:/# ") self.terminal.reset_mock()
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_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_ls_l(self): self.terminal.reset_mock() self._cmd('ls /computes -l') with assert_mock(self.terminal) as t: t.write('a---r-v-x root <transient> \tby-name/\t\n') skip(t, 1) no_more_calls(t) computes = db.get_root()['oms_root']['computes'] compute = self.make_compute() cid = computes.add(compute) transaction.commit() self.terminal.reset_mock() self._cmd('ls /computes -l') with assert_mock(self.terminal) as t: t.write('a---r-v-x root %s\t%s@\t/machines/%s : tux-for-test\n' % (datetime.datetime.fromtimestamp(compute.mtime).isoformat(), cid, cid)) t.write('a---r-v-x root <transient> \tby-name/\t\n') skip(t, 1) no_more_calls(t)
def test_ls_l(self): self.terminal.reset_mock() self._cmd('ls /computes -l') with assert_mock(self.terminal) as t: t.write( 'a---r-v-x root <transient> \tby-name/\t\n') skip(t, 1) no_more_calls(t) computes = db.get_root()['oms_root']['computes'] compute = self.make_compute() cid = computes.add(compute) transaction.commit() self.terminal.reset_mock() self._cmd('ls /computes -l') with assert_mock(self.terminal) as t: t.write('a---r-v-x root %s\t%s@\t/machines/%s : tux-for-test\n' % (datetime.datetime.fromtimestamp( compute.mtime).isoformat(), cid, cid)) t.write( 'a---r-v-x root <transient> \tby-name/\t\n') skip(t, 1) no_more_calls(t)
def test_skip(self): self.mock.foo() self.mock.foo() self.mock.foo() with assert_not_raises(): with assert_mock(self.mock) as m: skip(m, 3) with assert_not_raises(): with assert_mock(self.mock) as m: m.foo() skip(m, 2) with assert_raises(AssertionError) as cm: with assert_mock(self.mock) as m: skip(m, 4) assert cm.exception.args == ("There should be at least 4 more method calls but there are only 3", ) with assert_raises(AssertionError) as cm: with assert_mock(self.mock) as m: m.foo() skip(m, 4) assert cm.exception.args == ("There should be at least 4 more method calls but there are only 2", )
def test_suggestion(self): self._cmd('make') with assert_mock(self.terminal) as t: skip(t, 1) t.write("Do you mean 'mk'?\n")
def test_mandatory_positional(self): self._tab_after('cat ') with assert_mock(self.terminal) as t: skip(t, 4) no_more_calls(t)