def test_format_elemcreate(self): self.assertTrue(ttk._format_elemcreate(None), (None, ())) ## Testing type = image # image type expects at least an image name, so this should raise # IndexError since it tries to access the index 0 of an empty tuple self.assertRaises(IndexError, ttk._format_elemcreate, 'image') # don't format returned values as a tcl script # minimum acceptable for image type self.assertEqual(ttk._format_elemcreate('image', False, 'test'), ("test ", ())) # specifying a state spec self.assertEqual( ttk._format_elemcreate('image', False, 'test', ('', 'a')), ("test {} a", ())) # state spec with multiple states self.assertEqual( ttk._format_elemcreate('image', False, 'test', ('a', 'b', 'c')), ("test {a b} c", ())) # state spec and options res = ttk._format_elemcreate('image', False, 'test', ('a', 'b'), a='x', b='y') self.assertEqual(res[0], "test a b") self.assertEqual(set(res[1]), {"-a", "x", "-b", "y"}) # format returned values as a tcl script # state spec with multiple states and an option with a multivalue self.assertEqual( ttk._format_elemcreate('image', True, 'test', ('a', 'b', 'c', 'd'), x=[2, 3]), ("{test {a b c} d}", "-x {2 3}")) ## Testing type = vsapi # vsapi type expects at least a class name and a part_id, so this # should raise an ValueError since it tries to get two elements from # an empty tuple self.assertRaises(ValueError, ttk._format_elemcreate, 'vsapi') # don't format returned values as a tcl script # minimum acceptable for vsapi self.assertEqual(ttk._format_elemcreate('vsapi', False, 'a', 'b'), ("a b ", ())) # now with a state spec with multiple states self.assertEqual( ttk._format_elemcreate('vsapi', False, 'a', 'b', ('a', 'b', 'c')), ("a b {a b} c", ())) # state spec and option self.assertEqual( ttk._format_elemcreate('vsapi', False, 'a', 'b', ('a', 'b'), opt='x'), ("a b a b", ("-opt", "x"))) # format returned values as a tcl script # state spec with a multivalue and an option self.assertEqual( ttk._format_elemcreate('vsapi', True, 'a', 'b', ('a', 'b', [1, 2]), opt='x'), ("{a b {a b} {1 2}}", "-opt x")) # Testing type = from # from type expects at least a type name self.assertRaises(IndexError, ttk._format_elemcreate, 'from') self.assertEqual(ttk._format_elemcreate('from', False, 'a'), ('a', ())) self.assertEqual(ttk._format_elemcreate('from', False, 'a', 'b'), ('a', ('b', ))) self.assertEqual(ttk._format_elemcreate('from', True, 'a', 'b'), ('{a}', 'b'))
def test_format_elemcreate(self): self.assertTrue(ttk._format_elemcreate(None), (None, ())) self.assertRaises(IndexError, ttk._format_elemcreate, 'image') self.assertEqual(ttk._format_elemcreate('image', False, 'test'), ('test ', ())) self.assertEqual( ttk._format_elemcreate('image', False, 'test', ('', 'a')), ('test {} a', ())) self.assertEqual( ttk._format_elemcreate('image', False, 'test', ('a', 'b', 'c')), ('test {a b} c', ())) res = ttk._format_elemcreate('image', False, 'test', ('a', 'b'), a='x', b='y') self.assertEqual(res[0], 'test a b') self.assertEqual(set(res[1]), {'-a', 'x', '-b', 'y'}) self.assertEqual( ttk._format_elemcreate('image', True, 'test', ('a', 'b', 'c', 'd'), x=[2, 3]), ('{test {a b c} d}', '-x {2 3}')) self.assertRaises(ValueError, ttk._format_elemcreate, 'vsapi') self.assertEqual(ttk._format_elemcreate('vsapi', False, 'a', 'b'), ('a b ', ())) self.assertEqual( ttk._format_elemcreate('vsapi', False, 'a', 'b', ('a', 'b', 'c')), ('a b {a b} c', ())) self.assertEqual( ttk._format_elemcreate('vsapi', False, 'a', 'b', ('a', 'b'), opt='x'), ('a b a b', ('-opt', 'x'))) self.assertEqual( ttk._format_elemcreate('vsapi', True, 'a', 'b', ('a', 'b', [1, 2]), opt='x'), ('{a b {a b} {1 2}}', '-opt x')) self.assertRaises(IndexError, ttk._format_elemcreate, 'from') self.assertEqual(ttk._format_elemcreate('from', False, 'a'), ('a', ())) self.assertEqual(ttk._format_elemcreate('from', False, 'a', 'b'), ('a', ('b', ))) self.assertEqual(ttk._format_elemcreate('from', True, 'a', 'b'), ('{a}', 'b')) return
def test_format_elemcreate(self): self.assertTrue(ttk._format_elemcreate(None), (None, ())) ## Testing type = image # image type expects at least an image name, so this should raise # IndexError since it tries to access the index 0 of an empty tuple self.assertRaises(IndexError, ttk._format_elemcreate, 'image') # don't format returned values as a tcl script # minimum acceptable for image type self.assertEqual(ttk._format_elemcreate('image', False, 'test'), ("test ", ())) # specifying a state spec self.assertEqual(ttk._format_elemcreate('image', False, 'test', ('', 'a')), ("test {} a", ())) # state spec with multiple states self.assertEqual(ttk._format_elemcreate('image', False, 'test', ('a', 'b', 'c')), ("test {a b} c", ())) # state spec and options res = ttk._format_elemcreate('image', False, 'test', ('a', 'b'), a='x', b='y') self.assertEqual(res[0], "test a b") self.assertEqual(set(res[1]), {"-a", "x", "-b", "y"}) # format returned values as a tcl script # state spec with multiple states and an option with a multivalue self.assertEqual(ttk._format_elemcreate('image', True, 'test', ('a', 'b', 'c', 'd'), x=[2, 3]), ("{test {a b c} d}", "-x {2 3}")) ## Testing type = vsapi # vsapi type expects at least a class name and a part_id, so this # should raise an ValueError since it tries to get two elements from # an empty tuple self.assertRaises(ValueError, ttk._format_elemcreate, 'vsapi') # don't format returned values as a tcl script # minimum acceptable for vsapi self.assertEqual(ttk._format_elemcreate('vsapi', False, 'a', 'b'), ("a b ", ())) # now with a state spec with multiple states self.assertEqual(ttk._format_elemcreate('vsapi', False, 'a', 'b', ('a', 'b', 'c')), ("a b {a b} c", ())) # state spec and option self.assertEqual(ttk._format_elemcreate('vsapi', False, 'a', 'b', ('a', 'b'), opt='x'), ("a b a b", ("-opt", "x"))) # format returned values as a tcl script # state spec with a multivalue and an option self.assertEqual(ttk._format_elemcreate('vsapi', True, 'a', 'b', ('a', 'b', [1, 2]), opt='x'), ("{a b {a b} {1 2}}", "-opt x")) # Testing type = from # from type expects at least a type name self.assertRaises(IndexError, ttk._format_elemcreate, 'from') self.assertEqual(ttk._format_elemcreate('from', False, 'a'), ('a', ())) self.assertEqual(ttk._format_elemcreate('from', False, 'a', 'b'), ('a', ('b', ))) self.assertEqual(ttk._format_elemcreate('from', True, 'a', 'b'), ('{a}', 'b'))
def test_format_elemcreate(self): self.assertTrue(ttk._format_elemcreate(None), (None, ())) self.assertRaises(IndexError, ttk._format_elemcreate, 'image') self.assertEqual(ttk._format_elemcreate('image', False, 'test'), ('test ', ())) self.assertEqual(ttk._format_elemcreate('image', False, 'test', ('', 'a')), ('test {} a', ())) self.assertEqual(ttk._format_elemcreate('image', False, 'test', ('a', 'b', 'c')), ('test {a b} c', ())) res = ttk._format_elemcreate('image', False, 'test', ('a', 'b'), a='x', b='y') self.assertEqual(res[0], 'test a b') self.assertEqual(set(res[1]), {'-a', 'x', '-b', 'y'}) self.assertEqual(ttk._format_elemcreate('image', True, 'test', ('a', 'b', 'c', 'd'), x=[2, 3]), ('{test {a b c} d}', '-x {2 3}')) self.assertRaises(ValueError, ttk._format_elemcreate, 'vsapi') self.assertEqual(ttk._format_elemcreate('vsapi', False, 'a', 'b'), ('a b ', ())) self.assertEqual(ttk._format_elemcreate('vsapi', False, 'a', 'b', ('a', 'b', 'c')), ('a b {a b} c', ())) self.assertEqual(ttk._format_elemcreate('vsapi', False, 'a', 'b', ('a', 'b'), opt='x'), ('a b a b', ('-opt', 'x'))) self.assertEqual(ttk._format_elemcreate('vsapi', True, 'a', 'b', ('a', 'b', [1, 2]), opt='x'), ('{a b {a b} {1 2}}', '-opt x')) self.assertRaises(IndexError, ttk._format_elemcreate, 'from') self.assertEqual(ttk._format_elemcreate('from', False, 'a'), ('a', ())) self.assertEqual(ttk._format_elemcreate('from', False, 'a', 'b'), ('a', ('b',))) self.assertEqual(ttk._format_elemcreate('from', True, 'a', 'b'), ('{a}', 'b')) return