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 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 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)
Esempio n. 10
0
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)
Esempio n. 11
0
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)
Esempio n. 12
0
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)
Esempio n. 13
0
    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)
Esempio n. 14
0
    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))
Esempio n. 15
0
    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)
Esempio n. 16
0
    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))
Esempio n. 17
0
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)
Esempio n. 18
0
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)
Esempio n. 19
0
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)
Esempio n. 20
0
    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)
Esempio n. 21
0
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)
Esempio n. 22
0
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)
Esempio n. 23
0
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)
Esempio n. 24
0
    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)
Esempio n. 25
0
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)
Esempio n. 26
0
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)
Esempio n. 27
0
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)
Esempio n. 28
0
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)
Esempio n. 29
0
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)
Esempio n. 30
0
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)