<commit_before>import unittest
from .. import utils
from io import StringIO

metadata_text_1 = u"""
"isTs"\t"is1stLast"\t"prevCol"\t"del.t"\t"condName"
FALSE\t"e"\tNA\tNA\t"wt"
FALSE\t"e"\tNA\tNA\t"c1"
FALSE\t"l"\t"c4"\t5\t"c2"
FALSE\t"e"\tNA\tNA\t"c3"
FALSE\t"f"\tNA\tNA\t"c4"
FALSE\t"e"\tNA\tNA\t"c5"
""".strip()

class TestUtils(unittest.TestCase):

    def test_metadata_df(self):
        f = StringIO(metadata_text_1)
        df = utils.metadata_df(f)
        self.assertEqual({'del.t', 'is1stLast', 'isTs', 'prevCol'}, set(df.keys()))
        return df

    def test_metadata_dicts(self):
        df = self.test_metadata_df()
        dicts = utils.metadata_dicts(df)
        expect = {
            'wt': {'del.t': False, 'nextCol': None, 'isTs': False, 'prevCol': False, 'is1stLast': 'e'}, 
            'c3': {'del.t': False, 'nextCol': None, 'isTs': False, 'prevCol': False, 'is1stLast': 'e'}, 
            'c2': {'del.t': 5, 'nextCol': None, 'isTs': False, 'prevCol': 'c4', 'is1stLast': 'l'}, 
            'c1': {'del.t': False, 'nextCol': None, 'isTs': False, 'prevCol': False, 'is1stLast': 'e'}, 
            'c5': {'del.t': False, 'nextCol': None, 'isTs': False, 'prevCol': False, 'is1stLast': 'e'}, 
            'c4': {'del.t': False, 'nextCol': 'c2', 'isTs': False, 'prevCol': False, 'is1stLast': 'f'}
        }
        for name in dicts:
            d = dicts[name]
            e = expect[name]
            self.assertEqual(d, e)
        self.assertEqual(dicts, expect)

    def test_conditions_from_tsv(self):
        text = unicode(
            "\tcond1\tcond2\n"
            "gene1\t1\t2\n"
            "gene2\t3\t4\n"
            "gene3\t5\t4\n"
            )
        f = StringIO(text)
        conditions = utils.conditions_from_tsv(f)
        self.assertEqual(["cond1", "cond2"], conditions.keys())
        cond1 = conditions["cond1"]
        cgm = cond1.gene_mapping
        self.assertEqual({"gene1": 1, "gene2": 3, "gene3":5}, cgm.to_dict())
<commit_msg>fix py3 issue again<commit_after>import unittest
from .. import utils
from io import StringIO

metadata_text_1 = u"""
"isTs"\t"is1stLast"\t"prevCol"\t"del.t"\t"condName"
FALSE\t"e"\tNA\tNA\t"wt"
FALSE\t"e"\tNA\tNA\t"c1"
FALSE\t"l"\t"c4"\t5\t"c2"
FALSE\t"e"\tNA\tNA\t"c3"
FALSE\t"f"\tNA\tNA\t"c4"
FALSE\t"e"\tNA\tNA\t"c5"
""".strip()

class TestUtils(unittest.TestCase):

    def test_metadata_df(self):
        f = StringIO(metadata_text_1)
        df = utils.metadata_df(f)
        self.assertEqual({'del.t', 'is1stLast', 'isTs', 'prevCol'}, set(df.keys()))
        return df

    def test_metadata_dicts(self):
        df = self.test_metadata_df()
        dicts = utils.metadata_dicts(df)
        expect = {
            'wt': {'del.t': False, 'nextCol': None, 'isTs': False, 'prevCol': False, 'is1stLast': 'e'}, 
            'c3': {'del.t': False, 'nextCol': None, 'isTs': False, 'prevCol': False, 'is1stLast': 'e'}, 
            'c2': {'del.t': 5, 'nextCol': None, 'isTs': False, 'prevCol': 'c4', 'is1stLast': 'l'}, 
            'c1': {'del.t': False, 'nextCol': None, 'isTs': False, 'prevCol': False, 'is1stLast': 'e'}, 
            'c5': {'del.t': False, 'nextCol': None, 'isTs': False, 'prevCol': False, 'is1stLast': 'e'}, 
            'c4': {'del.t': False, 'nextCol': 'c2', 'isTs': False, 'prevCol': False, 'is1stLast': 'f'}
        }
        for name in dicts:
            d = dicts[name]
            e = expect[name]
            self.assertEqual(d, e)
        self.assertEqual(dicts, expect)

    def test_conditions_from_tsv(self):
        text = u"" + (
            "\tcond1\tcond2\n"
            "gene1\t1\t2\n"
            "gene2\t3\t4\n"
            "gene3\t5\t4\n"
            )
        f = StringIO(text)
        conditions = utils.conditions_from_tsv(f)
        self.assertEqual(["cond1", "cond2"], conditions.keys())
        cond1 = conditions["cond1"]
        cgm = cond1.gene_mapping
        self.assertEqual({"gene1": 1, "gene2": 3, "gene3":5}, cgm.to_dict())

{'fraction_non_alphanumeric': 0.19828239454407678, 'fraction_numerical': 0.023995958575397828, 'mean_word_length': 2.5675675675675675, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, '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': '2387676', 'n_tokens_mistral': 1592, 'n_tokens_neox': 1542, 'n_words': 291}