def _harmonize_subset_types(set_, subset_tuples): """Possibly convert an iterable of tuples with subsets of given "set", to an iterable of :class:`set` objects if original "set" was so too. """ # if argument is originally a set, return subsets also as sets; # otherwise (for non-set collection), return subsets as tuples if is_tuple(set_): return subset_tuples else: subset_class = set_.__class__ if is_set(set_) else tuple return imap(subset_class, subset_tuples)
def test_arg__some_object(self): self.assertFalse(__unit__.is_tuple(object()))
def test_arg__none(self): self.assertFalse(__unit__.is_tuple(None))
def _assertTuple(self, obj): self.assertTrue(is_tuple(obj), msg="%r is not a tuple" % (obj,))
def _assertTuple(self, obj): self.assertTrue(is_tuple(obj), msg="%r is not a tuple" % (obj, ))
def test_len__negative(self): with self.assertRaises(ValueError): __unit__.is_tuple(self.TUPLE, len_=-1)
def test_len__string(self): with self.assertRaises(TypeError): __unit__.is_tuple(self.TUPLE, len_="42")
def test_len__none(self): self.assertFalse(__unit__.is_tuple(None, len_=None)) self.assertFalse(__unit__.is_tuple(object())) self.assertTrue(__unit__.is_tuple(self.EMPTY_TUPLE, len_=None)) self.assertTrue(__unit__.is_tuple(self.TUPLE, len_=None))
def test_len__some_object(self): with self.assertRaises(TypeError): __unit__.is_tuple(self.TUPLE, len_=object())
def test_arg__nonempty_tuple(self): self.assertTrue(__unit__.is_tuple(self.TUPLE))
def test__arg__empty_tuple(self): self.assertTrue(__unit__.is_tuple(self.EMPTY_TUPLE))
def test_len__zero(self): self.assertTrue(__unit__.is_tuple(self.EMPTY_TUPLE, len_=0)) self.assertFalse(__unit__.is_tuple(self.TUPLE, len_=0))
def test_len__positive(self): self.assertFalse( __unit__.is_tuple(self.EMPTY_TUPLE, len_=self.TUPLE_SIZE)) self.assertTrue(__unit__.is_tuple(self.TUPLE, len_=self.TUPLE_SIZE)) self.assertFalse( __unit__.is_tuple(self.TUPLE, len_=self.TUPLE_SIZE + 1))