Example #1
0
 def test_item_types(self):
     l1 = List(item_type=Integer)
     l2 = List(item_type=Integer())
     for l in (l1, l2):
         with pytest.raises(ParseError):
             l.parse('foo')
         with pytest.raises(ParseError):
             l.parse('1,2,')
         with pytest.raises(ParseError):
             l.parse('1,foo')
         assert l.parse('1') == [1]
         assert l.parse('1,2') == [1, 2]
Example #2
0
 def test_with_invalid_types(self):
     for i in (str, bytes.fromhex):
         with pytest.raises(TypeError):
             List(item_type=i)
Example #3
0
 def test_separator_semicolon(self):
     l = List(';')
     assert l.parse('foo;bar') == ['foo', 'bar']
     assert l.parse('foo,bar') == ['foo,bar']
Example #4
0
 def test_empty_string(self):
     assert List().parse('') == ['']
Example #5
0
 def test_string_with_trailing_separator(self):
     assert List().parse('foo,bar,') == ['foo', 'bar', '']
Example #6
0
 def test_two_list_string(self):
     assert List().parse('foo,bar,baz') == ['foo', 'bar', 'baz']
Example #7
0
 def test_one_element_string(self):
     assert List().parse('foo') == ['foo']