Beispiel #1
0
    def test_format_layoutlist(self):
        def sample(indent=0, indent_size=2):
            return ttk._format_layoutlist([('a', {
                'other': [1, 2, 3],
                'children': [('b', {
                    'children': [('c', {
                        'children': [('d', {
                            'nice': 'opt'
                        })],
                        'something': (1, 2)
                    })]
                })]
            })],
                                          indent=indent,
                                          indent_size=indent_size)[0]

        def sample_expected(indent=0, indent_size=2):
            spaces = lambda amount=0: ' ' * (amount + indent)
            return ("%sa -other {1 2 3} -children {\n"
                    "%sb -children {\n"
                    "%sc -something {1 2} -children {\n"
                    "%sd -nice opt\n"
                    "%s}\n"
                    "%s}\n"
                    "%s}" %
                    (spaces(), spaces(indent_size), spaces(2 * indent_size),
                     spaces(3 * indent_size), spaces(
                         2 * indent_size), spaces(indent_size), spaces()))

        # empty layout
        self.assertEqual(ttk._format_layoutlist([])[0], '')

        # smallest (after an empty one) acceptable layout
        smallest = ttk._format_layoutlist([('a', None)], indent=0)
        self.assertEqual(smallest, ttk._format_layoutlist([('a', '')],
                                                          indent=0))
        self.assertEqual(smallest[0], 'a')

        # testing indentation levels
        self.assertEqual(sample(), sample_expected())
        for i in range(4):
            self.assertEqual(sample(i), sample_expected(i))
            self.assertEqual(sample(i, i), sample_expected(i, i))

        # invalid layout format, different kind of exceptions will be
        # raised

        # plain wrong format
        self.assertRaises(ValueError, ttk._format_layoutlist,
                          ['bad', 'format'])
        self.assertRaises(TypeError, ttk._format_layoutlist, None)
        # _format_layoutlist always expects the second item (in every item)
        # to act like a dict (except when the value evalutes to False).
        self.assertRaises(AttributeError, ttk._format_layoutlist, [('a', 'b')])
        # bad children formatting
        self.assertRaises(ValueError, ttk._format_layoutlist, [('name', {
            'children': {
                'a': None
            }
        })])
    def test_format_layoutlist(self):

        def sample(indent = 0, indent_size = 2):
            return ttk._format_layoutlist([('a', {'other': [1, 2, 3],
               'children': [('b', {'children': [('c', {'children': [('d', {'nice': 'opt'})],
                                             'something': (1, 2)})]})]})], indent=indent, indent_size=indent_size)[0]

        def sample_expected(indent = 0, indent_size = 2):
            spaces = lambda amount = 0: ' ' * (amount + indent)
            return '%sa -other {1 2 3} -children {\n%sb -children {\n%sc -something {1 2} -children {\n%sd -nice opt\n%s}\n%s}\n%s}' % (spaces(),
             spaces(indent_size),
             spaces(2 * indent_size),
             spaces(3 * indent_size),
             spaces(2 * indent_size),
             spaces(indent_size),
             spaces())

        self.assertEqual(ttk._format_layoutlist([])[0], '')
        smallest = ttk._format_layoutlist([('a', None)], indent=0)
        self.assertEqual(smallest, ttk._format_layoutlist([('a', '')], indent=0))
        self.assertEqual(smallest[0], 'a')
        self.assertEqual(sample(), sample_expected())
        for i in range(4):
            self.assertEqual(sample(i), sample_expected(i))
            self.assertEqual(sample(i, i), sample_expected(i, i))

        self.assertRaises(ValueError, ttk._format_layoutlist, ['bad', 'format'])
        self.assertRaises(TypeError, ttk._format_layoutlist, None)
        self.assertRaises(AttributeError, ttk._format_layoutlist, [('a', 'b')])
        self.assertRaises(ValueError, ttk._format_layoutlist, [('name', {'children': {'a': None}})])
        return
    def test_format_layoutlist(self):

        def sample(indent = 0, indent_size = 2):
            return ttk._format_layoutlist([('a', {'other': [1, 2, 3],
               'children': [('b', {'children': [('c', {'children': [('d', {'nice': 'opt'})],
                                             'something': (1, 2)})]})]})], indent=indent, indent_size=indent_size)[0]

        def sample_expected(indent = 0, indent_size = 2):
            spaces = lambda amount = 0: ' ' * (amount + indent)
            return '%sa -other {1 2 3} -children {\n%sb -children {\n%sc -something {1 2} -children {\n%sd -nice opt\n%s}\n%s}\n%s}' % (spaces(),
             spaces(indent_size),
             spaces(2 * indent_size),
             spaces(3 * indent_size),
             spaces(2 * indent_size),
             spaces(indent_size),
             spaces())

        self.assertEqual(ttk._format_layoutlist([])[0], '')
        smallest = ttk._format_layoutlist([('a', None)], indent=0)
        self.assertEqual(smallest, ttk._format_layoutlist([('a', '')], indent=0))
        self.assertEqual(smallest[0], 'a')
        self.assertEqual(sample(), sample_expected())
        for i in range(4):
            self.assertEqual(sample(i), sample_expected(i))
            self.assertEqual(sample(i, i), sample_expected(i, i))

        self.assertRaises(ValueError, ttk._format_layoutlist, ['bad', 'format'])
        self.assertRaises(TypeError, ttk._format_layoutlist, None)
        self.assertRaises(AttributeError, ttk._format_layoutlist, [('a', 'b')])
        self.assertRaises(ValueError, ttk._format_layoutlist, [('name', {'children': {'a': None}})])
        return
    def test_format_layoutlist(self):
        def sample(indent=0, indent_size=2):
            return ttk._format_layoutlist(
            [('a', {'other': [1, 2, 3], 'children':
                [('b', {'children':
                    [('c', {'children':
                        [('d', {'nice': 'opt'})], 'something': (1, 2)
                    })]
                })]
            })], indent=indent, indent_size=indent_size)[0]

        def sample_expected(indent=0, indent_size=2):
            spaces = lambda amount=0: ' ' * (amount + indent)
            return (
                "%sa -other {1 2 3} -children {\n"
                "%sb -children {\n"
                "%sc -something {1 2} -children {\n"
                "%sd -nice opt\n"
                "%s}\n"
                "%s}\n"
                "%s}" % (spaces(), spaces(indent_size),
                    spaces(2 * indent_size), spaces(3 * indent_size),
                    spaces(2 * indent_size), spaces(indent_size), spaces()))

        # empty layout
        self.failUnlessEqual(ttk._format_layoutlist([])[0], '')

        # _format_layoutlist always expects the second item (in every item)
        # to act like a dict (except when the value evalutes to False).
        self.failUnlessRaises(AttributeError,
            ttk._format_layoutlist, [('a', 'b')])

        smallest = ttk._format_layoutlist([('a', None)], indent=0)
        self.failUnlessEqual(smallest,
            ttk._format_layoutlist([('a', '')], indent=0))
        self.failUnlessEqual(smallest[0], 'a')

        # testing indentation levels
        self.failUnlessEqual(sample(), sample_expected())
        for i in range(4):
            self.failUnlessEqual(sample(i), sample_expected(i))
            self.failUnlessEqual(sample(i, i), sample_expected(i, i))

        # invalid layout format, different kind of exceptions will be
        # raised by internal functions

        # plain wrong format
        self.failUnlessRaises(ValueError, ttk._format_layoutlist,
            ['bad', 'format'])
        # will try to use iteritems in the 'bad' string
        self.failUnlessRaises(AttributeError, ttk._format_layoutlist,
           [('name', 'bad')])
        # bad children formatting
        self.failUnlessRaises(ValueError, ttk._format_layoutlist,
            [('name', {'children': {'a': None}})])
Beispiel #5
0
 def sample(indent=0, indent_size=2):
     return ttk._format_layoutlist(
     [('a', {'other': [1, 2, 3], 'children':
         [('b', {'children':
             [('c', {'children':
                 [('d', {'nice': 'opt'})], 'something': (1, 2)
             })]
         })]
     })], indent=indent, indent_size=indent_size)[0]
Beispiel #6
0
 def sample(indent=0, indent_size=2):
     return ttk._format_layoutlist(
     [('a', {'other': [1, 2, 3], 'children':
         [('b', {'children':
             [('c', {'children':
                 [('d', {'nice': 'opt'})], 'something': (1, 2)
             })]
         })]
     })], indent=indent, indent_size=indent_size)[0]
Beispiel #7
0
 def sample(indent=0, indent_size=2):
     return ttk._format_layoutlist(
         [
             (
                 "a",
                 {
                     "other": [1, 2, 3],
                     "children": [
                         (
                             "b",
                             {"children": [("c", {"children": [("d", {"nice": "opt"})], "something": (1, 2)})]},
                         )
                     ],
                 },
             )
         ],
         indent=indent,
         indent_size=indent_size,
     )[0]
Beispiel #8
0
    def test_format_layoutlist(self):
        def sample(indent=0, indent_size=2):
            return ttk._format_layoutlist(
                [
                    (
                        "a",
                        {
                            "other": [1, 2, 3],
                            "children": [
                                (
                                    "b",
                                    {"children": [("c", {"children": [("d", {"nice": "opt"})], "something": (1, 2)})]},
                                )
                            ],
                        },
                    )
                ],
                indent=indent,
                indent_size=indent_size,
            )[0]

        def sample_expected(indent=0, indent_size=2):
            spaces = lambda amount=0: " " * (amount + indent)
            return (
                "%sa -other {1 2 3} -children {\n"
                "%sb -children {\n"
                "%sc -something {1 2} -children {\n"
                "%sd -nice opt\n"
                "%s}\n"
                "%s}\n"
                "%s}"
                % (
                    spaces(),
                    spaces(indent_size),
                    spaces(2 * indent_size),
                    spaces(3 * indent_size),
                    spaces(2 * indent_size),
                    spaces(indent_size),
                    spaces(),
                )
            )

        # empty layout
        self.assertEqual(ttk._format_layoutlist([])[0], "")

        # smallest (after an empty one) acceptable layout
        smallest = ttk._format_layoutlist([("a", None)], indent=0)
        self.assertEqual(smallest, ttk._format_layoutlist([("a", "")], indent=0))
        self.assertEqual(smallest[0], "a")

        # testing indentation levels
        self.assertEqual(sample(), sample_expected())
        for i in range(4):
            self.assertEqual(sample(i), sample_expected(i))
            self.assertEqual(sample(i, i), sample_expected(i, i))

        # invalid layout format, different kind of exceptions will be
        # raised

        # plain wrong format
        self.assertRaises(ValueError, ttk._format_layoutlist, ["bad", "format"])
        self.assertRaises(TypeError, ttk._format_layoutlist, None)
        # _format_layoutlist always expects the second item (in every item)
        # to act like a dict (except when the value evalutes to False).
        self.assertRaises(AttributeError, ttk._format_layoutlist, [("a", "b")])
        # bad children formatting
        self.assertRaises(ValueError, ttk._format_layoutlist, [("name", {"children": {"a": None}})])