<commit_before>#
# Copyright (C). 2011, 2012 <NAME> <ssato at redhat.com>
#
import os.path
import os
import unittest

import anytemplate.utils as TT
import anytemplate.tests.common


class Test_00_functions(unittest.TestCase):

    def test_02_uniq(self):
        self.assertEquals(TT.uniq([]), [])
        self.assertEquals(TT.uniq([1, 4, 5, 1, 2, 3, 5, 10, 13, 2]),
                          [1, 4, 5, 2, 3, 10, 13])

    def test_03_chaincalls(self):
        self.assertEquals(TT.chaincalls([lambda x: x + 1, lambda x: x - 1], 1),
                          1)

    def test_04_normpath(self):
        self.assertEquals(TT.normpath("/tmp/../etc/hosts"), "/etc/hosts")
        self.assertEquals(TT.normpath("~root/t"), "/root/t")

    def test_04_normpath__relative(self):
        curdir = os.curdir
        relpath = "./a/b/c.txt"

        self.assertEquals(TT.normpath(relpath),
                          TT.normpath(os.path.join(curdir, relpath)))

    def test_05_flip(self):
        self.assertEquals(TT.flip((1, 3)), (3, 1))

    def test_06_concat(self):
        self.assertEquals(TT.concat([]), [])
        self.assertEquals(TT.concat(()), [])
        self.assertEquals(TT.concat([[1, 2, 3], [4, 5]]), [1, 2, 3, 4, 5])
        self.assertEquals(TT.concat([[1, 2, 3], [4, 5, [6, 7]]]),
                          [1, 2, 3, 4, 5, [6, 7]])
        self.assertEquals(TT.concat(((1, 2, 3), (4, 5, [6, 7]))),
                          [1, 2, 3, 4, 5, [6, 7]])
        self.assertEquals(TT.concat((i, i * 2) for i in range(3)),
                          [0, 0, 1, 2, 2, 4])

    def test_40_parse_filespec__w_type(self):
        self.assertEquals(TT.parse_filespec("json:a.json"),
                          [("a.json", "json")])

    def test_41_parse_filespec__wo_type(self):
        self.assertEquals(TT.parse_filespec("a.json"), [("a.json", None)])
<commit_msg>add test cases of anytemplate.utils.find_template_from_path<commit_after>#
# Copyright (C). 2011, 2012 <NAME> <ssato at redhat.com>
#
import os.path
import os
import unittest

import anytemplate.utils as TT
import anytemplate.tests.common


class Test_00_functions(unittest.TestCase):

    def test_02_uniq(self):
        self.assertEquals(TT.uniq([]), [])
        self.assertEquals(TT.uniq([1, 4, 5, 1, 2, 3, 5, 10, 13, 2]),
                          [1, 4, 5, 2, 3, 10, 13])

    def test_03_chaincalls(self):
        self.assertEquals(TT.chaincalls([lambda x: x + 1, lambda x: x - 1], 1),
                          1)

    def test_04_normpath(self):
        self.assertEquals(TT.normpath("/tmp/../etc/hosts"), "/etc/hosts")
        self.assertEquals(TT.normpath("~root/t"), "/root/t")

    def test_04_normpath__relative(self):
        curdir = os.curdir
        relpath = "./a/b/c.txt"

        self.assertEquals(TT.normpath(relpath),
                          TT.normpath(os.path.join(curdir, relpath)))

    def test_05_flip(self):
        self.assertEquals(TT.flip((1, 3)), (3, 1))

    def test_06_concat(self):
        self.assertEquals(TT.concat([]), [])
        self.assertEquals(TT.concat(()), [])
        self.assertEquals(TT.concat([[1, 2, 3], [4, 5]]), [1, 2, 3, 4, 5])
        self.assertEquals(TT.concat([[1, 2, 3], [4, 5, [6, 7]]]),
                          [1, 2, 3, 4, 5, [6, 7]])
        self.assertEquals(TT.concat(((1, 2, 3), (4, 5, [6, 7]))),
                          [1, 2, 3, 4, 5, [6, 7]])
        self.assertEquals(TT.concat((i, i * 2) for i in range(3)),
                          [0, 0, 1, 2, 2, 4])

    def test_40_parse_filespec__w_type(self):
        self.assertEquals(TT.parse_filespec("json:a.json"),
                          [("a.json", "json")])

    def test_41_parse_filespec__wo_type(self):
        self.assertEquals(TT.parse_filespec("a.json"), [("a.json", None)])

    def test_60_find_template_from_path__wo_paths(self):
        self.assertEquals(TT.find_template_from_path(__file__), __file__)

    def test_62_find_template_from_path__w_paths(self):
        fn = os.path.basename(__file__)
        fdir = os.path.dirname(__file__)

        self.assertEquals(TT.find_template_from_path(fn, [fdir]),
                          __file__)

    def test_64_find_template_from_path__none(self):
        self.assertTrue(TT.find_template_from_path("not_existing") is None)

{'fraction_non_alphanumeric': 0.1682636129936901, 'fraction_numerical': 0.04860948819817715, 'mean_word_length': 2.372734436564224, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1044110', 'n_tokens_mistral': 1657, 'n_tokens_neox': 1482, 'n_words': 304}