示例#1
0
文件: sets.py 项目: movermeyer/taipan
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)
示例#2
0
 def test_arg__some_object(self):
     self.assertFalse(__unit__.is_tuple(object()))
示例#3
0
 def test_arg__none(self):
     self.assertFalse(__unit__.is_tuple(None))
示例#4
0
 def _assertTuple(self, obj):
     self.assertTrue(is_tuple(obj), msg="%r is not a tuple" % (obj,))
示例#5
0
 def _assertTuple(self, obj):
     self.assertTrue(is_tuple(obj), msg="%r is not a tuple" % (obj, ))
示例#6
0
 def test_len__negative(self):
     with self.assertRaises(ValueError):
         __unit__.is_tuple(self.TUPLE, len_=-1)
示例#7
0
 def test_len__string(self):
     with self.assertRaises(TypeError):
         __unit__.is_tuple(self.TUPLE, len_="42")
示例#8
0
 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))
示例#9
0
 def test_len__some_object(self):
     with self.assertRaises(TypeError):
         __unit__.is_tuple(self.TUPLE, len_=object())
示例#10
0
 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))
示例#11
0
 def test_arg__nonempty_tuple(self):
     self.assertTrue(__unit__.is_tuple(self.TUPLE))
示例#12
0
 def test__arg__empty_tuple(self):
     self.assertTrue(__unit__.is_tuple(self.EMPTY_TUPLE))
示例#13
0
 def test_arg__some_object(self):
     self.assertFalse(__unit__.is_tuple(object()))
示例#14
0
 def test_arg__none(self):
     self.assertFalse(__unit__.is_tuple(None))
示例#15
0
 def test__arg__empty_tuple(self):
     self.assertTrue(__unit__.is_tuple(self.EMPTY_TUPLE))
示例#16
0
 def test_arg__nonempty_tuple(self):
     self.assertTrue(__unit__.is_tuple(self.TUPLE))
示例#17
0
 def test_len__string(self):
     with self.assertRaises(TypeError):
         __unit__.is_tuple(self.TUPLE, len_="42")
示例#18
0
 def test_len__some_object(self):
     with self.assertRaises(TypeError):
         __unit__.is_tuple(self.TUPLE, len_=object())
示例#19
0
 def test_len__zero(self):
     self.assertTrue(__unit__.is_tuple(self.EMPTY_TUPLE, len_=0))
     self.assertFalse(__unit__.is_tuple(self.TUPLE, len_=0))
示例#20
0
 def test_len__zero(self):
     self.assertTrue(__unit__.is_tuple(self.EMPTY_TUPLE, len_=0))
     self.assertFalse(__unit__.is_tuple(self.TUPLE, len_=0))
示例#21
0
 def test_len__negative(self):
     with self.assertRaises(ValueError):
         __unit__.is_tuple(self.TUPLE, len_=-1)
示例#22
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))
示例#23
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))