예제 #1
0
 def test_happy_days(self):
     '''Test various regular inputs'''
     assert list(flatten([[2, 3], 1, [5, [7, 8]]])) == [2, 3, 1, 5, [7, 8]]
     assert list(flatten([[2, 3], 1, [5, [7, 8]]], times=2)) == [2, 3, 1, 5, 7, 8]
     assert list(flatten([[2, 3], 1, [5, [7, 8]]], times=3)) == [2, 3, 1, 5, 7, 8]
     assert list(flatten([[2, 3], 1, [5, [7, 8]]], times=0)) == [[2, 3], 1, [5, [7, 8]]]
     
     # Deep things are left alone (not iterators turned into lists or lists turned into sets or ...
     iterator = iter([7, 8])
     assert list(flatten([iter([2, 3]), 1, [{1,2}, iterator]])) == [2, 3, 1, {1,2}, iterator]
     
예제 #2
0
 def test_empty(self, times):
     '''When flatten empty, return iter(empty)'''
     assert list(flatten([], times=times)) == []
예제 #3
0
 def test_invalid_times(self):
     with pytest.raises(ValueError):
         '''When times < 0, ValueError'''
         list(flatten([1], times=-1))