Example #1
0
    def test_plain_with_dict(self):
        out = Output(output.PLAIN_DICT)
        self.assertEqual(
            out.convert(), """+----------+----------------+
| Property | Value          |
+----------+----------------+
| foobar   | {"foo": "bar"} |
+----------+----------------+""")
Example #2
0
    def test_plain_simple(self):
        out = Output(output.PLAIN_SIMPLE)
        self.assertEqual(
            out.convert(), """+----------+-------+
| Property | Value |
+----------+-------+
| name     | john  |
+----------+-------+""")
Example #3
0
    def test_plain_with_list(self):
        out = Output(output.PLAIN_LIST)
        self.assertEqual(
            out.convert(), """+----------+----------------+
| Property | Value          |
+----------+----------------+
| foobar   | ['foo', 'bar'] |
+----------+----------------+""")
Example #4
0
    def test_plain_with_empty_list(self):
        out = Output(output.PLAIN_EMPTY_LIST)
        self.assertEqual(
            out.convert(), """+----------+-------+
| Property | Value |
+----------+-------+
| foobar   |       |
+----------+-------+""")
Example #5
0
    def test_plain_with_null(self):
        out = Output(output.PLAIN_NULL)
        self.assertEqual(
            out.convert(), """+----------+-------+
| Property | Value |
+----------+-------+
| foobar   |       |
+----------+-------+""")
Example #6
0
    def test_list_multiple_with_excludes(self):
        out = Output(output.LIST_SIMPLE, exclude=['key2'])
        self.assertEqual(
            out.convert(), """+------+
| key1 |
+------+
| foo1 |
| bar1 |
+------+""")
Example #7
0
    def test_list_simple(self):
        out = Output(output.LIST_SIMPLE)
        self.assertEqual(
            out.convert(), """+------+------+
| key1 | key2 |
+------+------+
| foo1 | foo2 |
| bar1 | bar2 |
+------+------+""")
Example #8
0
    def test_plain_multiple_with_excludes(self):
        out = Output(output.PLAIN_MULTIPLE, exclude=['city', 'age'])
        self.assertEqual(
            out.convert(), """+----------+-------+
| Property | Value |
+----------+-------+
| country  | FR    |
| name     | john  |
+----------+-------+""")
Example #9
0
    def test_list_with_dict(self):
        out = Output(output.LIST_DICT)
        self.assertEqual(
            out.convert(), """+----------------+
| key            |
+----------------+
| foo            |
| {"foo": "bar"} |
+----------------+""")
Example #10
0
    def test_list_with_list(self):
        out = Output(output.LIST_NON_EMPTY_LIST)
        self.assertEqual(
            out.convert(), """+----------------+
| key            |
+----------------+
| foo            |
| ['foo', 'bar'] |
+----------------+""")
Example #11
0
    def test_list_with_empty_list(self):
        out = Output(output.LIST_EMPTY_LIST)
        self.assertEqual(
            out.convert(), """+-----+
| key |
+-----+
| foo |
|     |
+-----+""")
Example #12
0
    def test_list_with_null(self):
        out = Output(output.LIST_NULL)
        self.assertEqual(
            out.convert(), """+-----+
| key |
+-----+
| foo |
|     |
+-----+""")
Example #13
0
    def test_list_missing_keys(self):
        out = Output(output.LIST_MISSING_FIELDS)
        self.assertEqual(
            out.convert(), """+------+------+
| key1 | key2 |
+------+------+
| foo1 |      |
|      | bar2 |
+------+------+""")
Example #14
0
    def test_list_sort(self):
        out = Output(output.LIST_TO_SORT, sort='key')
        self.assertEqual(
            out.convert(), """+-----+
| key |
+-----+
| a   |
| b   |
| c   |
| d   |
+-----+""")
Example #15
0
    def test_plain_multiple(self):
        out = Output(output.PLAIN_MULTIPLE)
        self.assertEqual(
            out.convert(), """+----------+-------+
| Property | Value |
+----------+-------+
| age      | 45    |
| city     | Lille |
| country  | FR    |
| name     | john  |
+----------+-------+""")
Example #16
0
    def table(self, data, custom_func=None, exclude=[], sort=None):
        """
        Print a pretty table unless the ``--json`` parameter is specified.

        If no custom function is given, use the ``Output`` class to generate
        the table."""
        try:
            json = self.json
        except AttributeError:
            json = False

        # Print the result as json
        if json:
            click.echo(_json.dumps(data))
            return

        # Use the custom function if provided
        if custom_func:
            self.echo(custom_func(data))
            return

        # Otherwise, print the table with Output class
        table = Output(data, exclude=exclude, sort=sort)
        self.echo(table.convert())