Пример #1
0
    def test_print_table(self):
        _inventory = {'rope': 1, 'torch': 6}
        expected_output = \
"""-----------------
item name | count
-----------------
     rope |     1
    torch |     6
-----------------"""
        saved_stdout = sys.stdout

        try:
            mocked_stdout = StringIO()
            sys.stdout = mocked_stdout
            print_table(_inventory)
            self.assertEqual(mocked_stdout.getvalue().strip(), expected_output)
        finally:
            sys.stdout = saved_stdout
Пример #2
0
    def test_print_table_count_desc(self):
        _inventory = {'rope': 1, 'torch': 6, 'blanket': 3}
        expected_output = \
"""-----------------
item name | count
-----------------
    torch |     6
  blanket |     3
     rope |     1
-----------------"""
        saved_stdout = sys.stdout

        try:
            mocked_stdout = StringIO()
            sys.stdout = mocked_stdout
            print_table(_inventory, "count,desc")
            self.assertEqual(mocked_stdout.getvalue().strip(), expected_output)
        finally:
            sys.stdout = saved_stdout
Пример #3
0
def print_board(board):

    for row in board:
        for char in row:
            if char == '#':
                print(background.blue + colours.Blue + char + colours.Barier,
                      end='')
            elif char == '@':
                print(colours.Blue + char, end='')
            elif char == '8':
                print(background.cyan + colours.Yellow + char + colours.Barier,
                      end='')
            elif char == '9':
                print(background.cyan + colours.Yellow + char + colours.Barier,
                      end='')
            elif char == '1':
                print(background.cyan + colours.Yellow + char + colours.Barier,
                      end='')
            elif char == '0':
                print(background.cyan + colours.Yellow + char + colours.Barier,
                      end='')
            elif char == '7':
                print(background.cyan + colours.Yellow + char + colours.Barier,
                      end='')
            elif char == '*':
                print(background.lightgrey + '⛰️' + colours.Barier, end='')
            elif char == '%':
                print(colours.Red + char + colours.Barier, end='')
            elif char == '<':
                print(colours.Red + char + colours.Barier, end='')
            elif char == '>':
                print(colours.Red + char + colours.Barier, end='')
            elif char == '(':
                print(colours.Red + char + colours.Barier, end='')
            elif char == ')':
                print(colours.Red + char + colours.Barier, end='')
            elif char == 'P':
                print(background.lightgrey + colours.Blue + char +
                      colours.Barier,
                      end='')
            else:
                print(colours.Green + char + colours.Barier, end='')
        print(end='\n')
    print(print_table(inventory))