Exemple #1
0
    def test_complete_context_dependent_no_context(self):
        """Test whether context dependent arguments are correctly built when the
        context argument (i.e. the `set` cmd `path` argument) is not yet present.

        """
        self._tab_after('set /comp')
        with assert_mock(self.terminal) as t:
            t.write('utes/')
            no_more_calls(t)
    def test_complete_context_dependent_no_context(self):
        """Test whether context dependent arguments are correctly built when the
        context argument (i.e. the `set` cmd `path` argument) is not yet present.

        """
        self._tab_after('set /comp')
        with assert_mock(self.terminal) as t:
            t.write('utes/')
            no_more_calls(t)
    def test_complete_positional_choice(self):
        self.oms_ssh.lineReceived('cd computes')

        self._tab_after('mk comp')
        with assert_mock(self.terminal) as t:
            t.write('ute ')
            no_more_calls(t)

        self._tab_after('comp')
        assert not self.terminal.method_calls
Exemple #4
0
    def test_complete_positional_choice(self):
        self.oms_ssh.lineReceived('cd computes')

        self._tab_after('mk comp')
        with assert_mock(self.terminal) as t:
            t.write('ute ')
            no_more_calls(t)

        self._tab_after('comp')
        assert not self.terminal.method_calls
    def test_no_more_calls(self):
        with assert_not_raises():
            with assert_mock(self.mock) as m:
                no_more_calls(m)

        self.mock.foo()

        with assert_raises(AssertionError) as cm:
            with assert_mock(self.mock) as m:
                no_more_calls(m)
        assert cm.exception.args == ("There should be no more method calls but there are: foo()", )
Exemple #6
0
    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_complete_keyword_switches_mk(self):
        self.oms_ssh.lineReceived('cd computes')

        self._tab_after('mk compute st')
        with assert_mock(self.terminal) as t:
            t.write('ate=')
            no_more_calls(t)

        self._tab_after('ina')
        with assert_mock(self.terminal) as t:
            t.write('ctive ')
            no_more_calls(t)
    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
Exemple #9
0
    def test_complete_keyword_switches_mk(self):
        self.oms_ssh.lineReceived('cd computes')

        self._tab_after('mk compute st')
        with assert_mock(self.terminal) as t:
            t.write('ate=')
            no_more_calls(t)

        self._tab_after('ina')
        with assert_mock(self.terminal) as t:
            t.write('ctive ')
            no_more_calls(t)
Exemple #10
0
    def test_complete_keyword_switches(self):
        computes = db.get_root()['oms_root']['computes']
        cid = computes.add(self.make_compute())
        transaction.commit()

        self._tab_after('set /computes/%s st' % cid)
        with assert_mock(self.terminal) as t:
            t.write('ate=')
            no_more_calls(t)

        self._tab_after('ina')
        with assert_mock(self.terminal) as t:
            t.write('ctive ')
            no_more_calls(t)
    def test_complete_keyword_switches(self):
        computes = db.get_root()['oms_root']['computes']
        cid = computes.add(self.make_compute())
        transaction.commit()

        self._tab_after('set /computes/%s st' % cid)
        with assert_mock(self.terminal) as t:
            t.write('ate=')
            no_more_calls(t)

        self._tab_after('ina')
        with assert_mock(self.terminal) as t:
            t.write('ctive ')
            no_more_calls(t)
Exemple #12
0
    def test_complete_consumed_keyword_switches_mk(self):
        """Test consuming of already completed switches when there are mandatory arguments."""
        self.oms_ssh.lineReceived('cd computes')

        self._tab_after('mk compute st')
        with assert_mock(self.terminal) as t:
            t.write('ate=')
            no_more_calls(t)

        self._tab_after('ina')
        with assert_mock(self.terminal) as t:
            t.write('ctive ')
            no_more_calls(t)

        self._tab_after('st')
        assert not self.terminal.method_calls
Exemple #13
0
    def test_complete_prefix(self):
        self._tab_after('he')
        with assert_mock(self.terminal) as t:
            t.write('l')
            no_more_calls(t)

        # hit tab twice
        self.terminal.reset_mock()
        self.oms_ssh.handle_TAB()

        with assert_mock(self.terminal) as t:
            t.write('')
            t.nextLine()
            t.write('help  hello\n')
            t.write(self.oms_ssh.ps[0] + 'hel')
            no_more_calls(t)
    def test_complete_consumed_keyword_switches_mk(self):
        """Test consuming of already completed switches when there are mandatory arguments."""
        self.oms_ssh.lineReceived('cd computes')

        self._tab_after('mk compute st')
        with assert_mock(self.terminal) as t:
            t.write('ate=')
            no_more_calls(t)

        self._tab_after('ina')
        with assert_mock(self.terminal) as t:
            t.write('ctive ')
            no_more_calls(t)

        self._tab_after('st')
        assert not self.terminal.method_calls
    def test_complete_prefix(self):
        self._tab_after('he')
        with assert_mock(self.terminal) as t:
            t.write('l')
            no_more_calls(t)

        # hit tab twice
        self.terminal.reset_mock()
        self.oms_ssh.handle_TAB()

        with assert_mock(self.terminal) as t:
            t.write('')
            t.nextLine()
            t.write('help  hello\n')
            t.write(self.oms_ssh.ps[0] + 'hel')
            no_more_calls(t)
    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)
Exemple #17
0
    def test_complete_mk_legal_types(self):
        """Test that only legal types are shown."""
        self.oms_ssh.lineReceived('cd computes')

        self._tab_after('mk net')
        assert not self.terminal.method_calls

        self.oms_ssh.handle_RETURN()
        self.terminal.reset_mock()

        self._tab_after('mk comp')
        #~ eq_(self.terminal.method_calls, [('write', ('ute ',), {})])
        with assert_mock(self.terminal) as t:
            t.write('ute ')
            no_more_calls(t)

        self._tab_after('arch')
        with assert_mock(self.terminal) as t:
            t.write('itecture=')
            no_more_calls(t)
    def test_complete_mk_legal_types(self):
        """Test that only legal types are shown."""
        self.oms_ssh.lineReceived('cd computes')

        self._tab_after('mk net')
        assert not self.terminal.method_calls

        self.oms_ssh.handle_RETURN()
        self.terminal.reset_mock()

        self._tab_after('mk comp')
        #~ eq_(self.terminal.method_calls, [('write', ('ute ',), {})])
        with assert_mock(self.terminal) as t:
            t.write('ute ')
            no_more_calls(t)

        self._tab_after('arch')
        with assert_mock(self.terminal) as t:
            t.write('itecture=')
            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_complete_mk_legal_types_interface(self):
        class ITest(Interface):
            pass

        class Test(Model):
            implements(ITest)

            def __init__(self):
                pass

        class TestInterfaceContainer(Container):
            __contains__ = ITest

        class TestClassContainer(Container):
            __contains__ = Test

        creatable_models['some-test'] = Test

        orig_current_object = commands.CreateObjCmd.current_obj

        try:
            commands.CreateObjCmd.current_obj = TestInterfaceContainer()
            self._tab_after('mk ')
            with assert_mock(self.terminal) as t:
                t.write('some-test ')
                no_more_calls(t)

            self.oms_ssh.handle_RETURN()
            self.terminal.reset_mock()

            commands.CreateObjCmd.current_obj = TestClassContainer()

            self._tab_after('mk ')
            with assert_mock(self.terminal) as t:
                t.write('some-test ')
                no_more_calls(t)
        finally:
            commands.CreateObjCmd.current_obj = orig_current_object
            del creatable_models['some-test']
Exemple #21
0
    def test_complete_mk_legal_types_interface(self):
        class ITest(Interface):
            pass

        class Test(Model):
            implements(ITest)

            def __init__(self):
                pass

        class TestInterfaceContainer(Container):
            __contains__ = ITest

        class TestClassContainer(Container):
            __contains__ = Test

        creatable_models['some-test'] = Test

        orig_current_object = commands.CreateObjCmd.current_obj

        try:
            commands.CreateObjCmd.current_obj = TestInterfaceContainer()
            self._tab_after('mk ')
            with assert_mock(self.terminal) as t:
                t.write('some-test ')
                no_more_calls(t)

            self.oms_ssh.handle_RETURN()
            self.terminal.reset_mock()

            commands.CreateObjCmd.current_obj = TestClassContainer()

            self._tab_after('mk ')
            with assert_mock(self.terminal) as t:
                t.write('some-test ')
                no_more_calls(t)
        finally:
            commands.CreateObjCmd.current_obj = orig_current_object
            del creatable_models['some-test']
    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_complete_switches(self):
        self._tab_after('quit ')
        with assert_mock(self.terminal) as t:
            no_more_calls(t)

        # hit tab twice
        self.oms_ssh.handle_TAB()
        with assert_mock(self.terminal) as t:
            no_more_calls(t)

        # now try with a dash
        self._tab_after('-')
        with assert_mock(self.terminal) as t:
            t.write('')
            t.nextLine()
            t.write('-h  --help\n')
            t.write(self.oms_ssh.ps[0] + 'quit -')
            no_more_calls(t)
        # disambiguate
        self._tab_after('-')
        with assert_mock(self.terminal) as t:
            t.write('help ')
            no_more_calls(t)
Exemple #24
0
    def test_complete_switches(self):
        self._tab_after('quit ')
        with assert_mock(self.terminal) as t:
            no_more_calls(t)

        # hit tab twice
        self.oms_ssh.handle_TAB()
        with assert_mock(self.terminal) as t:
            no_more_calls(t)

        # now try with a dash
        self._tab_after('-')
        with assert_mock(self.terminal) as t:
            t.write('')
            t.nextLine()
            t.write('-h  --help\n')
            t.write(self.oms_ssh.ps[0] + 'quit -')
            no_more_calls(t)
        # disambiguate
        self._tab_after('-')
        with assert_mock(self.terminal) as t:
            t.write('help ')
            no_more_calls(t)
 def test_command_arg_spaces_before_command(self):
     self._tab_after(' ls comp')
     with assert_mock(self.terminal) as t:
         t.write('utes/')
         no_more_calls(t)
Exemple #26
0
 def test_complete_quotes(self):
     self._tab_after('ls "comp')
     with assert_mock(self.terminal) as t:
         t.write('utes/')
         no_more_calls(t)
Exemple #27
0
 def test_complete_not_found(self):
     self._tab_after('asdasd')
     with assert_mock(self.terminal) as t:
         no_more_calls(t)
Exemple #28
0
 def test_command_completion_spaces(self):
     self._tab_after('    q')
     with assert_mock(self.terminal) as t:
         t.write('uit ')
         no_more_calls(t)
 def test_mandatory_positional(self):
     self._tab_after('cat ')
     with assert_mock(self.terminal) as t:
         skip(t, 4)
         no_more_calls(t)
 def test_command_completion_spaces(self):
     self._tab_after('    q')
     with assert_mock(self.terminal) as t:
         t.write('uit ')
         no_more_calls(t)
 def test_complete_not_found(self):
     self._tab_after('asdasd')
     with assert_mock(self.terminal) as t:
         no_more_calls(t)
 def test_complete_quotes(self):
     self._tab_after('ls "comp')
     with assert_mock(self.terminal) as t:
         t.write('utes/')
         no_more_calls(t)
Exemple #33
0
 def test_command_arg_spaces_before_command(self):
     self._tab_after(' ls comp')
     with assert_mock(self.terminal) as t:
         t.write('utes/')
         no_more_calls(t)
Exemple #34
0
 def test_mandatory_positional(self):
     self._tab_after('cat ')
     with assert_mock(self.terminal) as t:
         skip(t, 4)
         no_more_calls(t)