Exemple #1
0
 def test_disabled_header(self):
     self.printer = Printer(self.strategy, noheading=True)
     self.printer.set_header("heading")
     self.assert_calls(None, [])
Exemple #2
0
class PrinterTest(PrinterTestCase):

    def setUp(self):
        self.strategy = Mock()
        self.printer = Printer(self.strategy)

    def assert_calls(self, expected_header, expected_columns):
        self.printer.print_item({})
        self.strategy.print_item.assert_called_once_with(expected_header, expected_columns, {})
        self.printer.print_items({})
        self.strategy.print_items.assert_called_once_with(expected_header, expected_columns, {})

    def test_filter_columns_by_strategy(self):
        expected_columns = [{
            'attr_name': 'column_a',
            'name': 'A'
        }, {
            'attr_name': 'column_b',
            'name': 'B',
            'show_with': Mock
        }]
        columns_to_filter_out = [{
            'attr_name': 'column_c',
            'name': 'C',
            'show_with': VerboseStrategy
        }]

        for col in (expected_columns+columns_to_filter_out):
            self.printer.add_column(**col)
        self.assert_calls('', expected_columns)

    def test_all_columns_are_passed_to_strategy(self):
        expected_columns = [{
            'attr_name': 'column_a',
            'name': 'Important Column',
            'unknown_param': '???'
        }, {
            'attr_name': 'column_b',
            'name': 'Another Important Column',
            'formatter': Mock(),
            'item_formatter': Mock()
        }]

        for col in expected_columns:
            self.printer.add_column(**col)
        self.assert_calls('', expected_columns)


    def test_column_name_is_created_automatically(self):
        expected_column = {
            'attr_name': 'some_column',
            'name': 'Some Column'
        }
        self.printer.add_column('some_column')
        self.assert_calls('', [expected_column])

    def test_header_passed_to_strategy(self):
        self.printer.set_header("heading")
        self.assert_calls("heading", [])

    def test_disabled_header(self):
        self.printer = Printer(self.strategy, noheading=True)
        self.printer.set_header("heading")
        self.assert_calls(None, [])
Exemple #3
0
 def setUp(self):
     self.strategy = Mock()
     self.printer = Printer(self.strategy)
Exemple #4
0
 def create_printer(self, strategy):
     return Printer(strategy)