def test_string_type(self): # We are technically testing different things here in Python 2 and # Python 3, but in both cases a string (byte string or unicode string) # should not be a "sequence" by our definition. self.assertFalse(is_sequence("")) self.assertFalse(is_sequence(six.u(""))) self.assertFalse(is_sequence(six.b("")))
def warn(value): """Raises a Python UserWarning if `value` is not None. This is typically going to be used inside setter functions for deprecated fields. The deprecation warning shouldn't be raised when the field is being initialized to ``None``. """ if value is None: return if is_sequence(value) and not value: return fmt = "The use of this field has been deprecated. Received '{0}' object." msg = fmt.format(type(value).__name__) warnings.warn(msg)
def test_tuple_types(self): self.assertTrue(is_sequence(tuple())) self.assertTrue(is_sequence((1, 2, 3, 4)))
def test_set_types(self): self.assertTrue(is_sequence(set())) # Set literal syntax {1, 2, 3, 4} doesn't work on Python 2.6. self.assertTrue(is_sequence(set([1, 2, 3, 4])))
def test_list_types(self): self.assertTrue(is_sequence(list())) self.assertTrue(is_sequence([])) self.assertTrue(is_sequence([1, 2, 3, 4]))
def test_dict_types(self): self.assertTrue(is_sequence(dict())) self.assertTrue(is_sequence({})) self.assertTrue(is_sequence({1: 2, 3: 4}))