def set_test(self): st = {1, 2, 4, 5} func = lambda x: x ** 2 mapped_st = utils.keep_type_map(func, st) self.assertEqual(mapped_st, {1, 4, 16, 25}) self.assertIsInstance(mapped_st, set)
def tuple_test(self): tpl = (1, 2, 4, 5) func = lambda x: x ** 2 mapped_tpl = utils.keep_type_map(func, tpl) self.assertEqual(mapped_tpl, (1, 4, 16, 25)) self.assertIsInstance(mapped_tpl, tuple)
def str_test(self): stri = "abcd" func = lambda c: chr((ord(c) + 2) % 256) mapped_stri = utils.keep_type_map(func, stri) self.assertEqual(mapped_stri, "cdef") self.assertIsInstance(mapped_stri, str)
def set_test(self): st = {1, 2, 4, 5} func = lambda x: x**2 mapped_st = utils.keep_type_map(func, st) self.assertEqual(mapped_st, {1, 4, 16, 25}) self.assertIsInstance(mapped_st, set)
def list_test(self): lst = [1, 2, 4, 5] func = lambda x: x ** 2 mapped_lst = utils.keep_type_map(func, lst) self.assertEqual(mapped_lst, [1, 4, 16, 25]) self.assertIsInstance(mapped_lst, list)
def list_test(self): lst = [1, 2, 4, 5] func = lambda x: x**2 mapped_lst = utils.keep_type_map(func, lst) self.assertEqual(mapped_lst, [1, 4, 16, 25]) self.assertIsInstance(mapped_lst, list)
def tuple_test(self): tpl = (1, 2, 4, 5) func = lambda x: x**2 mapped_tpl = utils.keep_type_map(func, tpl) self.assertEqual(mapped_tpl, (1, 4, 16, 25)) self.assertIsInstance(mapped_tpl, tuple)
def test_namedtuple(): NT = namedtuple("TestingNT", ["a", "b"]) ntpl = NT(2, 4) mapped_tpl = utils.keep_type_map(lambda x: x ** 2, ntpl) assert mapped_tpl == NT(4, 16) assert isinstance(mapped_tpl, tuple) assert isinstance(mapped_tpl, NT)
def test_gen(): generator = (el for el in (1, 2, 4, 5)) mapped_generator = utils.keep_type_map(lambda x: x**2, generator) assert tuple(mapped_generator) == (1, 4, 16, 25) # any better test for this? assert "__next__" in dir(mapped_generator)
def test_gen(): generator = (el for el in (1, 2, 4, 5)) mapped_generator = utils.keep_type_map(lambda x: x ** 2, generator) assert tuple(mapped_generator) == (1, 4, 16, 25) # any better test for this? assert "__next__" in dir(mapped_generator)
def test_namedtuple(): NT = namedtuple("TestingNT", ["a", "b"]) ntpl = NT(2, 4) mapped_tpl = utils.keep_type_map(lambda x: x**2, ntpl) assert mapped_tpl == NT(4, 16) assert isinstance(mapped_tpl, tuple) assert isinstance(mapped_tpl, NT)
def namedtuple_test(self): NT = namedtuple("TestingNT", ["a", "b"]) ntpl = NT(2, 4) func = lambda x: x ** 2 mapped_tpl = utils.keep_type_map(func, ntpl) self.assertEqual(mapped_tpl, NT(4, 16)) self.assertIsInstance(mapped_tpl, tuple) self.assertIsInstance(mapped_tpl, NT)
def gen_test(self): gen = (it for it in [1, 2, 4, 5]) func = lambda x: x**2 mapped_gen = utils.keep_type_map(func, gen) self.assertEqual(tuple(mapped_gen), tuple([1, 4, 16, 25])) # any better test for this? self.assertIn("__next__", dir(mapped_gen))
def namedtuple_test(self): NT = namedtuple("TestingNT", ["a", "b"]) ntpl = NT(2, 4) func = lambda x: x**2 mapped_tpl = utils.keep_type_map(func, ntpl) self.assertEqual(mapped_tpl, NT(4, 16)) self.assertIsInstance(mapped_tpl, tuple) self.assertIsInstance(mapped_tpl, NT)
def gen_test(self): gen = (it for it in [1, 2, 4, 5]) func = lambda x: x ** 2 mapped_gen = utils.keep_type_map(func, gen) self.assertEqual(tuple(mapped_gen), tuple([1, 4, 16, 25])) # any better test for this? self.assertIn("next", dir(mapped_gen))
def strip_content_dir(fpaths, phase="preinst"): """ Strip content directory prefix from the file paths for either pre-installation or post-installation phase. :param fpaths: iterable of file paths to strip content directory prefix from :type fpaths: iterable of strings :param phase: specifies pre-installation or post-installation phase :type phase: "preinst" or "postinst" :return: the same iterable of file paths as given with the content directory prefix stripped :rtype: same type as fpaths """ if phase == "preinst": remove_prefix = lambda x: x[len(INSTALLATION_CONTENT_DIR):] else: remove_prefix = lambda x: x[len(TARGET_CONTENT_DIR):] return utils.keep_type_map(remove_prefix, fpaths)
def test_tuple(): tpl = (1, 2, 4, 5) mapped_tpl = utils.keep_type_map(lambda x: x**2, tpl) assert mapped_tpl == (1, 4, 16, 25) assert isinstance(mapped_tpl, tuple)
def dict_test(self): dct = {"a": 1, "b": 2} mapped_dct = utils.keep_type_map(str.upper, dct) self.assertEqual(list(mapped_dct.keys()), ["A", "B"]) self.assertIsInstance(mapped_dct, dict)
def test_set(): st = {1, 2, 4, 5} mapped_st = utils.keep_type_map(lambda x: x**2, st) assert mapped_st == {1, 4, 16, 25} assert isinstance(mapped_st, set)
def test_dict(): dct = {"a": 1, "b": 2} mapped_dct = utils.keep_type_map(str.upper, dct) assert list(mapped_dct.keys()) == ["A", "B"] assert isinstance(mapped_dct, dict)
def test_str(): stri = "abcd" mapped_stri = utils.keep_type_map(lambda c: chr((ord(c) + 2) % 256), stri) assert mapped_stri == "cdef" assert isinstance(mapped_stri, str)
def dict_test(self): dct = {"a": 1, "b": 2} mapped_dct = utils.keep_type_map(str.upper, dct) self.assertEqual(mapped_dct.keys(), ["A", "B"]) self.assertIsInstance(mapped_dct, dict)
def test_list(): lst = [1, 2, 4, 5] mapped_lst = utils.keep_type_map(lambda x: x**2, lst) assert mapped_lst == [1, 4, 16, 25] assert isinstance(mapped_lst, list)
def test_list(): lst = [1, 2, 4, 5] mapped_lst = utils.keep_type_map(lambda x: x ** 2, lst) assert mapped_lst == [1, 4, 16, 25] assert isinstance(mapped_lst, list)
def test_tuple(): tpl = (1, 2, 4, 5) mapped_tpl = utils.keep_type_map(lambda x: x ** 2, tpl) assert mapped_tpl == (1, 4, 16, 25) assert isinstance(mapped_tpl, tuple)
def test_set(): st = {1, 2, 4, 5} mapped_st = utils.keep_type_map(lambda x: x ** 2, st) assert mapped_st == {1, 4, 16, 25} assert isinstance(mapped_st, set)