Esempio n. 1
0
 def test_get_corrected_commands_with_rule_returns_list(self):
     rule = Rule(get_new_command=lambda x: [x.script + '!', x.script + '@'],
                 priority=100)
     assert (list(rule.get_corrected_commands(Command(script='test'))) == [
         CorrectedCommand(script='test!', priority=100),
         CorrectedCommand(script='test@', priority=200)
     ])
Esempio n. 2
0
def test_remove_duplicates():
    side_effect = lambda *_: None
    assert set(remove_duplicates([CorrectedCommand('ls', priority=100),
                                  CorrectedCommand('ls', priority=200),
                                  CorrectedCommand('ls', side_effect, 300)])) \
           == {CorrectedCommand('ls', priority=100),
               CorrectedCommand('ls', side_effect, 300)}
Esempio n. 3
0
 def test_get_corrected_commands_with_rule_returns_list(self):
     rule = Rule(get_new_command=lambda x: [x.script + "!", x.script + "@"],
                 priority=100)
     assert list(rule.get_corrected_commands(Command("test", ""))) == [
         CorrectedCommand(script="test!", priority=100),
         CorrectedCommand(script="test@", priority=200),
     ]
Esempio n. 4
0
 def test_with_rule_returns_list(self):
     rule = Rule(
         get_new_command=lambda x, _: [x.script + '!', x.script + '@'],
         priority=100)
     assert list(make_corrected_commands(Command(script='test'), [rule], None)) \
            == [CorrectedCommand(script='test!', priority=100),
                CorrectedCommand(script='test@', priority=200)]
Esempio n. 5
0
 def test_representable(self):
     assert ("{}".format(CorrectedCommand("ls", None, 100)) ==
             "CorrectedCommand(script=ls, side_effect=None, priority=100)")
     assert (
         u"{}".format(CorrectedCommand(u"echo café", None, 100)) ==
         u"CorrectedCommand(script=echo café, side_effect=None, priority=100)"
     )
Esempio n. 6
0
 def test_remove_duplicates(self, settings):
     side_effect = lambda *_: None
     seq = SortedCorrectedCommandsSequence(
         iter([CorrectedCommand('ls', priority=100),
               CorrectedCommand('ls', priority=200),
               CorrectedCommand('ls', side_effect, 300)]),
         settings)
     assert set(seq) == {CorrectedCommand('ls', priority=100),
                         CorrectedCommand('ls', side_effect, 300)}
Esempio n. 7
0
def test_organize_commands():
    """Ensures that the function removes duplicates and sorts commands."""
    commands = [CorrectedCommand('ls'), CorrectedCommand('ls -la', priority=9000),
                CorrectedCommand('ls -lh', priority=100),
                CorrectedCommand(u'echo café', priority=200),
                CorrectedCommand('ls -lh', priority=9999)]
    assert list(organize_commands(iter(commands))) \
        == [CorrectedCommand('ls'), CorrectedCommand('ls -lh', priority=100),
            CorrectedCommand(u'echo café', priority=200),
            CorrectedCommand('ls -la', priority=9000)]
Esempio n. 8
0
    def test_realises_generator_only_on_demand(self, settings):
        should_realise = False

        def gen():
            yield CorrectedCommand('git commit')
            yield CorrectedCommand('git branch', priority=200)
            assert should_realise
            yield CorrectedCommand('git checkout', priority=100)

        commands = SortedCorrectedCommandsSequence(gen(), settings)
        assert commands[0] == CorrectedCommand('git commit')
        should_realise = True
        assert commands[1] == CorrectedCommand('git checkout', priority=100)
        assert commands[2] == CorrectedCommand('git branch', priority=200)
Esempio n. 9
0
 def test_representable(self):
     assert '{}'.format(CorrectedCommand('ls', None, 100)) == \
            'CorrectedCommand(script=ls, side_effect=None, priority=100)'
     assert u'{}'.format(CorrectedCommand(u'echo café', None, 100)) == \
            u'CorrectedCommand(script=echo café, side_effect=None, priority=100)'
Esempio n. 10
0
 def test_hashable(self):
     assert {
         CorrectedCommand('ls', None, 100),
         CorrectedCommand('ls', None, 200)
     } == {CorrectedCommand('ls')}
Esempio n. 11
0
 def test_equality(self):
     assert (CorrectedCommand('ls', None,
                              100) == CorrectedCommand('ls', None, 200))
     assert (CorrectedCommand('ls', None, 100) != CorrectedCommand(
         'ls', lambda *_: _, 100))
Esempio n. 12
0
 def test_run(self, capsys, settings, script, printed, override_settings):
     settings.update(override_settings)
     CorrectedCommand(script, None, 1000).run(Command())
     out, _ = capsys.readouterr()
     assert out[:-1] == printed
Esempio n. 13
0
 def test_get_corrected_commands_with_rule_returns_command(self):
     rule = Rule(get_new_command=lambda x: x.script + '!', priority=100)
     assert list(rule.get_corrected_commands(Command(script='test'))) \
            == [CorrectedCommand(script='test!', priority=100)]
Esempio n. 14
0
 def test_hashable(self):
     assert {
         CorrectedCommand("ls", None, 100),
         CorrectedCommand("ls", None, 200),
     } == {CorrectedCommand("ls")}
Esempio n. 15
0
 def test_equality(self):
     assert CorrectedCommand("ls", None,
                             100) == CorrectedCommand("ls", None, 200)
     assert CorrectedCommand("ls", None, 100) != CorrectedCommand(
         "ls", lambda *_: _, 100)
Esempio n. 16
0
 def gen():
     yield CorrectedCommand('git commit')
     yield CorrectedCommand('git branch', priority=200)
     assert should_realise
     yield CorrectedCommand('git checkout', priority=100)