def test_with_no_values_returns_error(self): self.type_instance = types.String(choices=[]) self.assertInvalid('foo')
def test_string_with_non_closed_quote_is_invalid(self): self.type_instance = types.String(quotes=True) self.assertInvalid('"foo bar') self.assertInvalid("'bar baz")
def test_listed_value(self): self.type_instance = types.String(choices=['foo', 'bar']) self.assertConvertedValue('foo', 'foo')
def test_unlisted_value(self): self.type_instance = types.String(choices=['foo', 'bar']) self.assertInvalid('baz')
def test_bounds_required(self): self.type_instance = types.Dict(types.String(), bounds=True) self.assertInvalid('foo:bar,baz:123') self.assertInvalid('{foo:bar,baz:123') self.assertInvalid('foo:bar,baz:123}')
def test_not_equal_with_non_equal_custom_item_types(self): it1 = types.Integer() it2 = types.String() self.assertFalse(it1 == it2) self.assertFalse(types.Dict(it1) == types.Dict(it2))
def test_dict_of_values_containing_commas(self): self.type_instance = types.Dict(types.String(quotes=True)) self.assertConvertedValue('foo:"bar, baz",bam:quux', { 'foo': 'bar, baz', 'bam': 'quux' })
def test_bounds_parsing(self): self.type_instance = types.Dict(types.String(), bounds=True) self.assertConvertedValue('{foo:bar,baz:123}', { 'foo': 'bar', 'baz': '123' })
class StringTypeTests(TypeTestHelper, unittest.TestCase): type = types.String() def test_empty_string_passes(self): self.assertConvertedValue('', '') def test_should_return_same_string_if_valid(self): self.assertConvertedValue('foo bar', 'foo bar') def test_listed_value(self): self.type_instance = types.String(choices=['foo', 'bar']) self.assertConvertedValue('foo', 'foo') def test_unlisted_value(self): self.type_instance = types.String(choices=['foo', 'bar']) self.assertInvalid('baz') def test_with_no_values_returns_error(self): self.type_instance = types.String(choices=[]) self.assertInvalid('foo') def test_string_with_non_closed_quote_is_invalid(self): self.type_instance = types.String(quotes=True) self.assertInvalid('"foo bar') self.assertInvalid("'bar baz") def test_quotes_are_stripped(self): self.type_instance = types.String(quotes=True) self.assertConvertedValue('"foo bar"', 'foo bar') def test_trailing_quote_is_ok(self): self.type_instance = types.String(quotes=True) self.assertConvertedValue('foo bar"', 'foo bar"') def test_repr(self): t = types.String() self.assertEqual('String', repr(t)) def test_repr_with_choices(self): t = types.String(choices=['foo', 'bar']) self.assertEqual('String(choices=[\'foo\', \'bar\'])', repr(t)) def test_equal(self): self.assertTrue(types.String() == types.String()) def test_equal_with_same_choices(self): t1 = types.String(choices=['foo', 'bar']) t2 = types.String(choices=['foo', 'bar']) self.assertTrue(t1 == t2) def test_not_equal_with_different_choices(self): t1 = types.String(choices=['foo', 'bar']) t2 = types.String(choices=['foo', 'baz']) self.assertFalse(t1 == t2) def test_equal_with_equal_quote_falgs(self): t1 = types.String(quotes=True) t2 = types.String(quotes=True) self.assertTrue(t1 == t2) def test_not_equal_with_different_quote_falgs(self): t1 = types.String(quotes=False) t2 = types.String(quotes=True) self.assertFalse(t1 == t2) def test_not_equal_to_other_class(self): self.assertFalse(types.String() == types.Integer())
def test_list_of_lists(self): self.type_instance = types.List(types.List(types.String(), bounds=True)) self.assertConvertedValue('[foo],[bar, baz],[bam]', [['foo'], ['bar', 'baz'], ['bam']])
def test_list_of_values_containing_commas(self): self.type_instance = types.List(types.String(quotes=True)) self.assertConvertedValue('foo,"bar, baz",bam', ['foo', 'bar, baz', 'bam'])
def test_not_equal_to_other_class(self): self.assertFalse(types.Integer() == types.String())
def test_not_equal_to_other_class(self): self.assertFalse(types.Boolean() == types.String())