Beispiel #1
0
    def test_line_wrapping(self, print_mock, termsize_mock, _, __):
        """Test how the `output` method handles wrapping lines that are too long"""
        output = Output()

        # We only need a column value for the terminal size
        termsize_tuple = namedtuple('termsize_tuple', 'columns')
        termsize_mock.return_value = termsize_tuple(10)

        output._results = [  # pylint: disable=protected-access
            'short',  # no truncation - too short
            'looooooong',  # truncation - too long
            'tenchars',  # no truncation - exactly the right width
            '\x1b[0;31mshort\x1b[0m',  # no truncation - too short
            '\x1b[0;31mlooooooong\x1b[0m'  # truncation - too long, long word truncated
        ]
        output.output()

        print_mock.assert_called_with("""\
W short
O \x1b[0m...
O tenchars
O \x1b[0;31mshort\x1b[0m
O \x1b[0;31m\x1b[0m...\x1b[0m\
""")
        # Check that `print` has been called only once.
        # `unittest.mock.Mock.assert_called_once` is not available against Python < 3.6.
        self.assertEqual(print_mock.call_count, 1)
Beispiel #2
0
    def test_line_wrapping(self, print_mock, termsize_mock, _, __, ___, ____):
        """Test how the `output` method handles wrapping lines that are too long"""
        output = Output()

        # We only need a column value for the terminal size
        termsize_tuple = namedtuple('termsize_tuple', 'columns')
        termsize_mock.return_value = termsize_tuple(13)

        output._results = [  # pylint: disable=protected-access
            'short',  # no truncation - too short
            'looooooong',  # truncation - too long
            'adjusted',  # no truncation - exactly the right width
            '\x1b[0;31mshort\x1b[0m',  # no truncation - too short
            '\x1b[0;31mlooooooong\x1b[0m'  # truncation - too long, long word truncated
        ]
        output.output()

        print_mock.assert_called_with("""\
W    short
O    \x1b[0m...
O    adjusted
O    \x1b[0;31mshort\x1b[0m
O    \x1b[0;31m\x1b[0m...\x1b[0m\
""")
        # Check that `print` has been called only once.
        self.assertTrue(print_mock.assert_called_once)
Beispiel #3
0
    def test_centered_output(self, print_mock, _, __):
        """Test how the `output` method handles centering operations"""
        output = Output()

        # # ODD ENTRIES NUMBER # #
        # Entries smaller than logo
        output._results = [  # pylint: disable=protected-access
            '1', '2', '3'
        ]
        # Let's run the algorithm !
        output.output()
        self.assertListEqual(
            output._results,  # pylint: disable=protected-access
            [
                '', '', '', '', '', '', '', '1', '2', '3', '', '', '', '', '',
                '', '', ''
            ])

        # Entries bigger than logo
        output._results = [  # pylint: disable=protected-access
            '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12',
            '13', '14', '15', '16', '17', '18', '19', '20', '21'
        ]
        output.output()
        print_mock.assert_called_with("""\
FAKE_COLOR 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
FAKE_COLOR 20
FAKE_COLOR 21\x1b[0m\
""")

        # # EVEN ENTRIES NUMBER # #
        # Entries smaller than logo
        output._results = [  # pylint: disable=protected-access
            '1', '2', '3', '4'
        ]
        output.output()
        self.assertListEqual(
            output._results,  # pylint: disable=protected-access
            [
                '', '', '', '', '', '', '', '1', '2', '3', '4', '', '', '', '',
                '', '', ''
            ])

        # Entries bigger than logo
        output._results = [  # pylint: disable=protected-access
            '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12',
            '13', '14', '15', '16', '17', '18', '19', '20', '21', '22'
        ]
        output.output()
        print_mock.assert_called_with("""\
FAKE_COLOR 1
FAKE_COLOR 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
FAKE_COLOR 21
FAKE_COLOR 22\x1b[0m\
""")

        # # FULL ENTRIES # #
        output._results = [  # pylint: disable=protected-access
            '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12',
            '13', '14', '15', '16', '17', '18'
        ]
        output.output()
        self.assertListEqual(
            output._results,  # pylint: disable=protected-access
            [
                '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12',
                '13', '14', '15', '16', '17', '18'
            ])

        # # NO ENTRY # #
        output._results = []  # pylint: disable=protected-access
        output.output()
        self.assertListEqual(
            output._results,  # pylint: disable=protected-access
            [
                '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
                '', ''
            ])
Beispiel #4
0
    def test_centered_output(self, _, __, ___, ____):
        """Test how the `output` method handles centering operations"""
        output = Output()

        # # ODD ENTRIES NUMBER # #
        output._results = [  # pylint: disable=protected-access
            '1',
            '2',
            '3'
        ]
        # Let's run the algorithm !
        output.output()
        self.assertListEqual(
            output._results,  # pylint: disable=protected-access
            [
                '', '', '', '', '', '', '',
                '1', '2', '3',
                '', '', '', '', '', '', '', ''
            ]
        )

        # # EVEN ENTRIES NUMBER # #
        output._results = [  # pylint: disable=protected-access
            '1',
            '2',
            '3',
            '4'
        ]
        output.output()
        self.assertListEqual(
            output._results,  # pylint: disable=protected-access
            [
                '', '', '', '', '', '', '',
                '1', '2', '3', '4',
                '', '', '', '', '', '', ''
            ]
        )

        # # FULL ENTRIES # #
        output._results = [  # pylint: disable=protected-access
            '1', '2', '3', '4', '5', '6',
            '7', '8', '9', '10', '11', '12',
            '13', '14', '15', '16', '17', '18'
        ]
        output.output()
        self.assertListEqual(
            output._results,  # pylint: disable=protected-access
            [
                '1', '2', '3', '4', '5', '6',
                '7', '8', '9', '10', '11', '12',
                '13', '14', '15', '16', '17', '18'
            ]
        )

        # # NO ENTRY # #
        output._results = []  # pylint: disable=protected-access
        output.output()
        self.assertListEqual(
            output._results,  # pylint: disable=protected-access
            [
                '', '', '', '', '', '',
                '', '', '', '', '', '',
                '', '', '', '', '', '',
            ]
        )
Beispiel #5
0
    def test_centered_output(self, print_mock, _, __, ___):
        """Test how the `output` method handles centering operations"""
        output = Output()

        with self.subTest(
                'Odd number of entries (entries smaller than logo).'):
            output._results = [  # pylint: disable=protected-access
                '1', '2', '3'
            ]
            output.output()
            self.assertListEqual(
                output._results,  # pylint: disable=protected-access
                [
                    '', '', '', '', '', '', '', '1', '2', '3', '', '', '', '',
                    '', '', '', ''
                ])

        with self.subTest('Odd number of entries (entries bigger than logo).'):
            output._results = [  # pylint: disable=protected-access
                '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12',
                '13', '14', '15', '16', '17', '18', '19', '20', '21'
            ]
            output.output()
            print_mock.assert_called_with("""\
FAKE_COLOR    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
FAKE_COLOR    20
FAKE_COLOR    21\x1b[0m\
""")

        output = Output()

        with self.subTest(
                'Even number of entries (entries smaller than logo).'):
            output._results = [  # pylint: disable=protected-access
                '1', '2', '3', '4'
            ]
            output.output()
            self.assertListEqual(
                output._results,  # pylint: disable=protected-access
                [
                    '', '', '', '', '', '', '', '1', '2', '3', '4', '', '', '',
                    '', '', '', ''
                ])

        with self.subTest(
                'Even number of entries (entries bigger than logo).'):
            output._results = [  # pylint: disable=protected-access
                '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12',
                '13', '14', '15', '16', '17', '18', '19', '20', '21', '22'
            ]
            output.output()
            print_mock.assert_called_with("""\
FAKE_COLOR    1
FAKE_COLOR    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
FAKE_COLOR    21
FAKE_COLOR    22\x1b[0m\
""")

        output = Output()

        with self.subTest('Full entries.'):
            output._results = [  # pylint: disable=protected-access
                '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12',
                '13', '14', '15', '16', '17', '18'
            ]
            output.output()
            self.assertListEqual(
                output._results,  # pylint: disable=protected-access
                [
                    '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11',
                    '12', '13', '14', '15', '16', '17', '18'
                ])

        output = Output()

        with self.subTest('No entry.'):
            output._results = []  # pylint: disable=protected-access
            output.output()
            self.assertListEqual(
                output._results,  # pylint: disable=protected-access
                [
                    '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
                    '', '', ''
                ])