Example #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], '')

        # _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')])

        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 by internal functions

        # plain wrong format
        self.assertRaises(ValueError, ttk._format_layoutlist,
            ['bad', 'format'])
        # will try to use iteritems in the 'bad' string
        self.assertRaises(AttributeError, ttk._format_layoutlist,
           [('name', 'bad')])
        # bad children formatting
        self.assertRaises(ValueError, ttk._format_layoutlist,
            [('name', {'children': {'a': None}})])
Example #2
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], '')

        # _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')])

        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 by internal functions

        # plain wrong format
        self.assertRaises(ValueError, ttk._format_layoutlist,
            ['bad', 'format'])
        # will try to use iteritems in the 'bad' string
        self.assertRaises(AttributeError, ttk._format_layoutlist,
           [('name', 'bad')])
        # bad children formatting
        self.assertRaises(ValueError, ttk._format_layoutlist,
            [('name', {'children': {'a': None}})])
Example #3
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 {
%sb -children {
%sc -something {1 2} -children {
%sd -nice opt
%s}
%s}
%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], '')
        self.assertRaises(AttributeError, ttk._format_layoutlist, [('a', 'b')])
        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(AttributeError, ttk._format_layoutlist,
                          [('name', 'bad')])
        self.assertRaises(ValueError, ttk._format_layoutlist, [('name', {
            'children': {
                'a': None
            }
        })])
Example #4
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]
Example #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]
Example #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]
Example #7
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.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}})])