def test_empty_list(self): """ An edge case. Checks whether an empty list is correctly processed. """ l = list(scan._split([])) self.assertEqual(l, [])
def test_single_element(self): """ An edge case. Checks whether a single element is correctly processed. """ l = list(scan._split(['value'])) self.assertEqual(len(l), 1) self.assertEqual(l[0], ['value'])
def test_split_lengths(self): """ A normal use case. Checks whether length of individual chunks does not exceed resource limits. """ rng = int(self._patches['fd_res_lim'].new.return_value[0] * 5) lim = int(scan._file_descriptor_resource_limit() * scan._MAGIC_NUMBER_SPLIT_UPPER_THRESHOLD) for l in scan._split(range(rng)): self.assertLessEqual(len(l), lim)
def test_limit_exceeded(self): """ A rare case Checks whether length of individual chunks is always 1 after FD limit is exceeded. """ lim_u = int(scan._file_descriptor_resource_limit() * scan._MAGIC_NUMBER_SPLIT_UPPER_THRESHOLD) lim_l = int(scan._file_descriptor_resource_limit() * scan._MAGIC_NUMBER_SPLIT_LOWER_THRESHOLD) rng = int(self._patches['fd_res_lim'].new.return_value[0] * lim_l) o_fd_mock = self._patches['o_fds'].new self.assertLess(o_fd_mock.return_value, lim_l) for l in scan._split(range(rng)): if o_fd_mock.return_value < lim_l: self.assertTrue(1 < len(l) <= lim_u) o_fd_mock.return_value += 1 else: self.assertEqual(len(l), 1) self.assertGreaterEqual(o_fd_mock.return_value, lim_l)