Exemple #1
0
 def test_command_no_args_reg_prefix(self):
     # Covers command: not empty string and args: len 0, prefix: len > 0
     cmd_prefix = "!"
     command = Command("test", [], "testuser", cmd_prefix)
     self.assertEqual(cmd_prefix + "test", command.get_text())
     self.assertEqual("test", command.get_command())
     self.assertEqual([], command.get_args())
Exemple #2
0
 def test_command_and_args_empty_prefix(self):
     # Covers command: not empty string and args: len >0, prefix: len = 0
     cmd_prefix = ""
     command = Command("test", ['test'], "testuser", cmd_prefix)
     self.assertEqual(cmd_prefix + "test test", command.get_text())
     self.assertEqual("test", command.get_command())
     self.assertEqual(['test'], command.get_args())
Exemple #3
0
 def setUp(self):
     self.command = Command('module1', 'test1', 'foo1')
     self.rows = [
         ['module2', 'test2', 'foo0', False],
         ['module1', 'test1', 'foo1', True],
         ['module2', 'test3', 'foo4', False],
     ]
     self.names = ['user{}'.format(number) for number in range(1, 100)]
def test_parse_commands_returns_list_of_commands_with_all_directions() -> None:
    commands = parse_commands([
        'forward 17',
        'down 5',
        'up 3',
    ])

    assert commands == [
        Command(Direction.FORWARD, 17),
        Command(Direction.DOWN, 5),
        Command(Direction.UP, 3),
    ]
Exemple #5
0
 def test_equal(self):
     for row in self.rows:
         command = Command(*row[:3])
         if row[3]:
             self.assertEqual(command, self.command)
         else:
             self.assertNotEqual(command, self.command)
def test_position_move_decreases_y_value_given_an_up_command() -> None:
    position = Position()

    new_position = position.move(Command(Direction.UP, 2))

    assert new_position.x == 0
    assert new_position.y == -2
def test_position_move_increases_y_value_given_a_down_command() -> None:
    position = Position()

    new_position = position.move(Command(Direction.DOWN, 2))

    assert new_position.x == 0
    assert new_position.y == 2
def test_position_move_increases_x_value_given_a_forward_command() -> None:
    position = Position()

    new_position = position.move(Command(Direction.FORWARD, 5))

    assert new_position.x == 5
    assert new_position.y == 0
def test_position_with_aim_changes_x_and_y_given_an_forward_command() -> None:
    position = PositionWithAim(aim=5)

    new_position = position.move(Command(Direction.FORWARD, 3))

    assert new_position.aim == 5
    assert new_position.x == 3
    assert new_position.y == 15
Exemple #10
0
def test_position_with_aim_decreases_aim_given_an_up_command() -> None:
    position = PositionWithAim()

    new_position = position.move(Command(Direction.UP, 2))

    assert new_position.aim == -2
    assert new_position.x == 0
    assert new_position.y == 0
Exemple #11
0
def test_position_with_aim_increases_aim_given_a_down_command() -> None:
    position = PositionWithAim()

    new_position = position.move(Command(Direction.DOWN, 3))

    assert new_position.aim == 3
    assert new_position.x == 0
    assert new_position.y == 0
Exemple #12
0
class TestMashtab(unittest.TestCase):
    def setUp(self):
        self.command = Command('module1', 'test1', 'foo1')
        self.rows = [
            ['module2', 'test2', 'foo0', False],
            ['module1', 'test1', 'foo1', True],
            ['module2', 'test3', 'foo4', False],
        ]
        self.names = ['user{}'.format(number) for number in range(1, 100)]

    def test_equal(self):
        for row in self.rows:
            command = Command(*row[:3])
            if row[3]:
                self.assertEqual(command, self.command)
            else:
                self.assertNotEqual(command, self.command)

    def test_add_user(self):
        for user_name in self.names:
            self.command.add_param(user_name)
        for user_name in ['user1'] * 100:
            self.command.add_param(user_name)
        self.assertTrue(len(self.command.param) == len(self.names))

    def test_get_dict_command(self):
        self.command.add_param('user1')
        self.assertEqual(
            self.command.get_dict_command(), {
                'module': 'module1',
                'name': 'test1',
                'function': 'foo1',
                'param': [
                    'user1',
                ]
            })
        self.command.add_param('user2')
        self.assertEqual(
            self.command.get_dict_command(), {
                'module': 'module1',
                'name': 'test1',
                'function': 'foo1',
                'param': ['user1', 'user2']
            })
Exemple #13
0
def cmd(request):
    ret = Command()
    ret.send_text = mock.Mock()
    ret.subscribe = mock.Mock()
    ret.unsubscribe = mock.Mock()
    ret.channels = {'#interesting_channel'}
    ret.orders = collections.defaultdict(Order)
    ret.names = IdNameMap({'a': 'a-fullname', 'b': 'b-fullname'})
    return ret