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]
def test_with_invalid_types(self): for i in (str, bytes.fromhex): with pytest.raises(TypeError): List(item_type=i)
def test_separator_semicolon(self): l = List(';') assert l.parse('foo;bar') == ['foo', 'bar'] assert l.parse('foo,bar') == ['foo,bar']
def test_empty_string(self): assert List().parse('') == ['']
def test_string_with_trailing_separator(self): assert List().parse('foo,bar,') == ['foo', 'bar', '']
def test_two_list_string(self): assert List().parse('foo,bar,baz') == ['foo', 'bar', 'baz']
def test_one_element_string(self): assert List().parse('foo') == ['foo']