def test_format_mapdict(self):
        opts = {'a': [('b', 'c', 'val'), ('d', 'otherval'), ('', 'single')]}
        result = ttk._format_mapdict(opts)
        self.assertEqual(len(result), len(opts.keys()) * 2)
        self.assertEqual(result, ('-a', '{b c} val d otherval {} single'))
        self.assertEqual(ttk._format_mapdict(opts, script=True),
                         ('-a', '{{b c} val d otherval {} single}'))
        self.assertEqual(ttk._format_mapdict({2: []}), ('-2', ''))
        opts = {u'\xfc\xf1\xed\u0107\xf3d\xe8': [(u'\xe1', u'v\xe3l')]}
        result = ttk._format_mapdict(opts)
        self.assertEqual(result,
                         (u'-\xfc\xf1\xed\u0107\xf3d\xe8', u'\xe1 v\xe3l'))
        valid = {'opt': [('', u'', 'hi')]}
        self.assertEqual(ttk._format_mapdict(valid), ('-opt', '{ } hi'))
        invalid = {'opt': [(1, 2, 'valid val')]}
        self.assertRaises(TypeError, ttk._format_mapdict, invalid)
        invalid = {'opt': [([1], '2', 'valid val')]}
        self.assertRaises(TypeError, ttk._format_mapdict, invalid)
        valid = {'opt': [[1, 'value']]}
        self.assertEqual(ttk._format_mapdict(valid), ('-opt', '1 value'))
        for stateval in (None, 0, False, '', set()):
            valid = {'opt': [(stateval, 'value')]}
            self.assertEqual(ttk._format_mapdict(valid), ('-opt', '{} value'))

        opts = {'a': None}
        self.assertRaises(TypeError, ttk._format_mapdict, opts)
        self.assertRaises(IndexError, ttk._format_mapdict,
                          {'a': [('invalid', )]})
        return
    def test_format_mapdict(self):
        opts = {'a': [('b', 'c', 'val'), ('d', 'otherval'), ('', 'single')]}
        result = ttk._format_mapdict(opts)
        self.assertEqual(len(result), len(opts.keys()) * 2)
        self.assertEqual(result, ('-a', '{b c} val d otherval {} single'))
        self.assertEqual(ttk._format_mapdict(opts, script=True), ('-a', '{{b c} val d otherval {} single}'))
        self.assertEqual(ttk._format_mapdict({2: []}), ('-2', ''))
        opts = {u'\xfc\xf1\xed\u0107\xf3d\xe8': [(u'\xe1', u'v\xe3l')]}
        result = ttk._format_mapdict(opts)
        self.assertEqual(result, (u'-\xfc\xf1\xed\u0107\xf3d\xe8', u'\xe1 v\xe3l'))
        valid = {'opt': [('', u'', 'hi')]}
        self.assertEqual(ttk._format_mapdict(valid), ('-opt', '{ } hi'))
        invalid = {'opt': [(1, 2, 'valid val')]}
        self.assertRaises(TypeError, ttk._format_mapdict, invalid)
        invalid = {'opt': [([1], '2', 'valid val')]}
        self.assertRaises(TypeError, ttk._format_mapdict, invalid)
        valid = {'opt': [[1, 'value']]}
        self.assertEqual(ttk._format_mapdict(valid), ('-opt', '1 value'))
        for stateval in (None,
         0,
         False,
         '',
         set()):
            valid = {'opt': [(stateval, 'value')]}
            self.assertEqual(ttk._format_mapdict(valid), ('-opt', '{} value'))

        opts = {'a': None}
        self.assertRaises(TypeError, ttk._format_mapdict, opts)
        self.assertRaises(IndexError, ttk._format_mapdict, {'a': [('invalid',)]})
        return
Exemple #3
0
    def test_format_mapdict(self):
        opts = {'a': [('b', 'c', 'val'), ('d', 'otherval'), ('', 'single')]}
        result = ttk._format_mapdict(opts)
        self.assertEqual(len(result), len(opts.keys()) * 2)
        self.assertEqual(result, ('-a', '{b c} val d otherval {} single'))
        self.assertEqual(ttk._format_mapdict(opts, script=True),
            ('-a', '{{b c} val d otherval {} single}'))

        self.assertEqual(ttk._format_mapdict({2: []}), ('-2', ''))

        opts = {u'üñíćódè': [(u'á', u'vãl')]}
        result = ttk._format_mapdict(opts)
        self.assertEqual(result, (u'-üñíćódè', u'á vãl'))

        # empty states
        valid = {'opt': [('', u'', 'hi')]}
        self.assertEqual(ttk._format_mapdict(valid), ('-opt', '{ } hi'))

        # when passing multiple states, they all must be strings
        invalid = {'opt': [(1, 2, 'valid val')]}
        self.assertRaises(TypeError, ttk._format_mapdict, invalid)
        invalid = {'opt': [([1], '2', 'valid val')]}
        self.assertRaises(TypeError, ttk._format_mapdict, invalid)
        # but when passing a single state, it can be anything
        valid = {'opt': [[1, 'value']]}
        self.assertEqual(ttk._format_mapdict(valid), ('-opt', '1 value'))
        # special attention to single states which evalute to False
        for stateval in (None, 0, False, '', set()): # just some samples
            valid = {'opt': [(stateval, 'value')]}
            self.assertEqual(ttk._format_mapdict(valid),
                ('-opt', '{} value'))

        # values must be iterable
        opts = {'a': None}
        self.assertRaises(TypeError, ttk._format_mapdict, opts)

        # items in the value must have size >= 2
        self.assertRaises(IndexError, ttk._format_mapdict,
            {'a': [('invalid', )]})
Exemple #4
0
    def test_format_mapdict(self):
        opts = {'a': [('b', 'c', 'val'), ('d', 'otherval'), ('', 'single')]}
        result = ttk._format_mapdict(opts)
        self.failUnlessEqual(len(result), len(opts.keys()) * 2)
        self.failUnlessEqual(result, ('-a', '{b c} val d otherval {} single'))
        self.failUnlessEqual(ttk._format_mapdict(opts, script=True),
            ('-a', '{{b c} val d otherval {} single}'))

        self.failUnlessEqual(ttk._format_mapdict({2: []}), ('-2', ''))

        opts = {u'üñíćódè': [(u'á', u'vãl')]}
        result = ttk._format_mapdict(opts)
        self.failUnlessEqual(result, (u'-üñíćódè', u'á vãl'))

        # empty states
        valid = {'opt': [('', u'', 'hi')]}
        self.failUnlessEqual(ttk._format_mapdict(valid), ('-opt', '{ } hi'))

        # when passing multiple states, they all must be strings
        invalid = {'opt': [(1, 2, 'valid val')]}
        self.failUnlessRaises(TypeError, ttk._format_mapdict, invalid)
        invalid = {'opt': [([1], '2', 'valid val')]}
        self.failUnlessRaises(TypeError, ttk._format_mapdict, invalid)
        # but when passing a single state, it can be anything
        valid = {'opt': [[1, 'value']]}
        self.failUnlessEqual(ttk._format_mapdict(valid), ('-opt', '1 value'))
        # special attention to single states which evalute to False
        for stateval in (None, 0, False, '', set()): # just some samples
            valid = {'opt': [(stateval, 'value')]}
            self.failUnlessEqual(ttk._format_mapdict(valid),
                ('-opt', '{} value'))

        # values must be iterable
        opts = {'a': None}
        self.failUnlessRaises(TypeError, ttk._format_mapdict, opts)

        # items in the value must have size >= 2
        self.failUnlessRaises(IndexError, ttk._format_mapdict,
            {'a': [('invalid', )]})
    def test_format_mapdict(self):
        opts = {"a": [("b", "c", "val"), ("d", "otherval"), ("", "single")]}
        result = ttk._format_mapdict(opts)
        self.assertEqual(len(result), len(opts.keys()) * 2)
        self.assertEqual(result, ("-a", "{b c} val d otherval {} single"))
        self.assertEqual(ttk._format_mapdict(opts, script=True), ("-a", "{{b c} val d otherval {} single}"))

        self.assertEqual(ttk._format_mapdict({2: []}), ("-2", ""))

        opts = {u"üñíćódè": [(u"á", u"vãl")]}
        result = ttk._format_mapdict(opts)
        self.assertEqual(result, (u"-üñíćódè", u"á vãl"))

        # empty states
        valid = {"opt": [("", u"", "hi")]}
        self.assertEqual(ttk._format_mapdict(valid), ("-opt", "{ } hi"))

        # when passing multiple states, they all must be strings
        invalid = {"opt": [(1, 2, "valid val")]}
        self.assertRaises(TypeError, ttk._format_mapdict, invalid)
        invalid = {"opt": [([1], "2", "valid val")]}
        self.assertRaises(TypeError, ttk._format_mapdict, invalid)
        # but when passing a single state, it can be anything
        valid = {"opt": [[1, "value"]]}
        self.assertEqual(ttk._format_mapdict(valid), ("-opt", "1 value"))
        # special attention to single states which evalute to False
        for stateval in (None, 0, False, "", set()):  # just some samples
            valid = {"opt": [(stateval, "value")]}
            self.assertEqual(ttk._format_mapdict(valid), ("-opt", "{} value"))

        # values must be iterable
        opts = {"a": None}
        self.assertRaises(TypeError, ttk._format_mapdict, opts)

        # items in the value must have size >= 2
        self.assertRaises(IndexError, ttk._format_mapdict, {"a": [("invalid",)]})