<commit_before>#! /usr/bin/env python
# Last Change: Fri Nov 16 01:00 PM 2007 J

# test module for utils module
import os
import unittest

from utils import pkg_to_path, _rsplit, DefaultDic

class PkgToPathTester(unittest.TestCase):
    def setUp(self):
        self.pkg1 = "foo"
        self.pkg2 = "foo.bar"

        self.path1_expected = "foo"
        self.path2_expected = "foo" + os.sep + "bar"

    def test1(self):
        assert pkg_to_path(self.pkg1) == self.path1_expected
        assert pkg_to_path(self.pkg2) == self.path2_expected

class RsplitTester(unittest.TestCase):
    def test1(self):
        a1 = 'a.b.c'
        assert a1.split('.', -1) == a1.rsplit('.', -1) == _rsplit(a1, '.', -1)
        assert a1.rsplit('.', 1) == _rsplit(a1, '.', 1)
        assert a1.rsplit('.', 0) == _rsplit(a1, '.', 0)
        assert a1.rsplit('.', 2) == _rsplit(a1, '.', 2)

    def test2(self):
        a2 = 'floupi'
        assert a2.rsplit('.') ==  _rsplit(a2, '.', -1)
        assert a2.rsplit('.', 1) == _rsplit(a2, '.', 1)

class DefaultDicTester(unittest.TestCase):
    def test_basic1(self):
        d = DefaultDic(('a', 'b'))
        a = d['a']
        b = d['b']

    def test_defval(self):
        d = DefaultDic(('a', 'b'), default = 1)
        a = d['a']
        b = d['b']
        assert a == b == 1

    def test_nonav(self):
        # Check that setting a key not given in the ctor fails
        d = DefaultDic(('a', 'b'))
        d['a'] = 1 
        try:
            d['c'] = 2
            raise AssertionError('Setting a non existing key succeeded, should have failed.')
        except KeyError:
            pass

if __name__ == "__main__":
    unittest.main()<commit_msg>Correct DefaultDict typo in utils tests<commit_after>#! /usr/bin/env python
# Last Change: Fri Nov 16 01:00 PM 2007 J

# test module for utils module
import os
import unittest

from utils import pkg_to_path, _rsplit, DefaultDict

class PkgToPathTester(unittest.TestCase):
    def setUp(self):
        self.pkg1 = "foo"
        self.pkg2 = "foo.bar"

        self.path1_expected = "foo"
        self.path2_expected = "foo" + os.sep + "bar"

    def test1(self):
        assert pkg_to_path(self.pkg1) == self.path1_expected
        assert pkg_to_path(self.pkg2) == self.path2_expected

class RsplitTester(unittest.TestCase):
    def test1(self):
        a1 = 'a.b.c'
        assert a1.split('.', -1) == a1.rsplit('.', -1) == _rsplit(a1, '.', -1)
        assert a1.rsplit('.', 1) == _rsplit(a1, '.', 1)
        assert a1.rsplit('.', 0) == _rsplit(a1, '.', 0)
        assert a1.rsplit('.', 2) == _rsplit(a1, '.', 2)

    def test2(self):
        a2 = 'floupi'
        assert a2.rsplit('.') ==  _rsplit(a2, '.', -1)
        assert a2.rsplit('.', 1) == _rsplit(a2, '.', 1)

class DefaultDictTester(unittest.TestCase):
    def test_basic1(self):
        d = DefaultDict(('a', 'b'))
        a = d['a']
        b = d['b']

    def test_defval(self):
        d = DefaultDict(('a', 'b'), default = 1)
        a = d['a']
        b = d['b']
        assert a == b == 1

    def test_nonav(self):
        # Check that setting a key not given in the ctor fails
        d = DefaultDict(('a', 'b'))
        d['a'] = 1 
        try:
            d['c'] = 2
            raise AssertionError('Setting a non existing key succeeded, should have failed.')
        except KeyError:
            pass

if __name__ == "__main__":
    unittest.main()
{'fraction_non_alphanumeric': 0.16427104722792607, 'fraction_numerical': 0.031094162511000292, 'mean_word_length': 2.2291666666666665, 'pattern_counts': {'":': 2, '<': 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': '942224', 'n_tokens_mistral': 1284, 'n_tokens_neox': 1229, 'n_words': 312}