Пример #1
0
 def test_array_input_not_allowed_element_error(self):
     with self.assertRaises(TypeError) as not_allowed:
         flatten(['hello world'], (int))
     self.assertEqual(
         str(not_allowed.exception),
         ("Array must contain (<type 'list'>, <type 'tuple'>, <type 'set'>)"
          " or <type 'int'>"))
Пример #2
0
 def test_non_array_input_error(self):
     with self.assertRaises(TypeError) as non_array:
         flatten('hello world')
     self.assertEqual(
         str(non_array.exception),
         "Input must be in (<type 'list'>, <type 'tuple'>, <type 'set'>)")
Пример #3
0
 def test_recursion(self):
     self.assertEqual(flatten([1, [2, [3, ['a', [self.mocked_object]]]]]),
                      [1, 2, 3, 'a', self.mocked_object])
Пример #4
0
 def test_empty_list(self):
     self.assertEqual(flatten([]), [])
Пример #5
0
 def test_no_recursion(self):
     self.assertEqual(flatten([1, 'a', self.mocked_object]),
                      [1, 'a', self.mocked_object])