<commit_before>from .. import scheduler

from collections import namedtuple
import unittest

class TestPrefReader(unittest.TestCase):
    """ Tests for the functions to read preferences. """

    def test_employee_names(self):
        """ Test that get_all_prefs() gets the right employee names. """

        assert scheduler.get_all_prefs("tests/test_prefs") == 2

    def test_combine_lines(self):
        """ Test that combine_lines() properly combines lines. """

        lines = ['nm2("Test Employee","",2,"id");sc("40");', 
                 'tb(0,4);lorem;ipsum;',
                 'nm2("Test Another","",3,"id");sc("50");',
                 'tc(0,5,"3");'
                 ]

        Employee = namedtuple("Employee", ["name", "prefs"])
        expected_empls = [Employee('Test Employee', 'tb(0,4);lorem;ipsum;'),
                          Employee('Test Another', 'tc(0,5,"3");')]

        combined = scheduler.combine_lines(lines)
        print (combined)
        assert combined == expected_empls

    def test_combine_lines_removes_script_tags(self):
        """ Test combine_lines() removes script tags. """

        lines = ['<script>nm2("Test Employee","",2,"id");sc("40");', 
                 'tb(0,4);lorem;ipsum;',
                 '</script>',
                 'nm2("Test Another","",3,"id");sc("50");',
                 'tc(0,5,"3");'
                 ]

        Employee = namedtuple("Employee", ["name", "prefs"])
        expected_empls = [Employee('Test Employee', 'tb(0,4);lorem;ipsum;'),
                          Employee('Test Another', 'tc(0,5,"3");')]

        combined = scheduler.combine_lines(lines)
        print (combined)
        assert combined == expected_empls<commit_msg>Add tests for pref string conversion<commit_after>from .. import scheduler

from collections import namedtuple
import unittest

class TestPrefReader(unittest.TestCase):
    """ Tests for the functions to read preferences. """

    def test_combine_lines(self):
        """ Test that combine_lines() properly combines lines. """

        lines = ['nm2("Test Employee","",2,"id");sc("40");', 
                 'tb(0,4);lorem;ipsum;',
                 'nm2("Test Another","",3,"id");sc("50");',
                 'tc(0,5,"3");'
                 ]

        Employee = namedtuple("Employee", ["name", "prefs"])
        expected_empls = [Employee('Test Employee', 'tb(0,4);lorem;ipsum;'),
                          Employee('Test Another', 'tc(0,5,"3");')]

        combined = scheduler.combine_lines(lines)
        print (combined)
        assert combined == expected_empls

    def test_combine_lines_removes_script_tags(self):
        """ Test combine_lines() removes script tags. """

        lines = ['<script>nm2("Test Employee","",2,"id");sc("40");', 
                 'tb(0,4);lorem;ipsum;',
                 '</script>',
                 'nm2("Test Another","",3,"id");sc("50");',
                 'tc(0,5,"3");'
                 ]

        Employee = namedtuple("Employee", ["name", "prefs"])
        expected_empls = [Employee('Test Employee', 'tb(0,4);lorem;ipsum;'),
                          Employee('Test Another', 'tc(0,5,"3");')]

        combined = scheduler.combine_lines(lines)
        print (combined)
        assert combined == expected_empls

    def test_get_day_prefs_simple(self):
        """ Test get_day_prefs() on the dummy set of prefs. """

        Employee = namedtuple("Employee", ["name", "prefs"])

        actual_prefs = scheduler.get_day_prefs("tests/test_prefs")
        expected = [Employee('Some Employee', 'XXXXXXXXXXXXDDDDDDDDPPPPPPCCCCCCCCCCCCCCCCXXXXXXXXXX'),
                    Employee('Test Student', 'XXXXXXCCCCCCCCCCCCCCCCCCCCXXPPPPPPPPPPPPPPPPXXXXXXXX')]


        assert actual_prefs == expected

    def test_its_fine_if_this_fails(self):
        """ Intentionally failing so I can get printed stuff. """

        assert 1
        #assert scheduler.get_day_prefs("tests/test_prefs") == 0

class TestPrefsLineConversion(unittest.TestCase):
    """ Tests for the functions that convert prefs lines to strings. """

    def test_simple_uncolored_conversion(self):
        """ Test a conversion from one tb(..) piece. """
        line = 'tb(0,4);'
        expected = 'XXXX'

        assert scheduler.prefs_line_to_string(line) == expected

    def test_simple_colored_conversion(self):
        """ Test a conversion for a green tc(..) piece. """
        line = 'tc(4,8,"1");'
        expected = 'PPPPPPPP'

        assert scheduler.prefs_line_to_string(line) == expected

    def test_simple_colored_conversion(self):
        """ Test a conversion for a pink tc(..) piece. """
        line = 'tc(4,6,"2");'
        expected = 'DDDDDD'

        assert scheduler.prefs_line_to_string(line) == expected

    def test_simple_colored_conversion(self):
        """ Test a conversion for a red tc(..) piece. """
        line = 'tc(4,4,"3");'
        expected = 'CCCC'

        assert scheduler.prefs_line_to_string(line) == expected

    def test_double_conversion(self):
        """ Test a conversion with two pieces. """
        line = 'tc(2,4,"1");tb(0,8);'
        expected = 'PPPPXXXXXXXX'

        assert scheduler.prefs_line_to_string(line) == expected

    def test_multiple_conversion(self):
        """ Test a conversion with multiple pieces. """
        line = 'tb(0,4);tc(0,14,"3");tc(2,2,"1");tc(0,26,"3");tb(2,6);etr();'
        expected = 'XXXXCCCCCCCCCCCCCCPPCCCCCCCCCCCCCCCCCCCCCCCCCCXXXXXX'

        assert scheduler.prefs_line_to_string(line) == expected

{'fraction_non_alphanumeric': 0.15582533067584708, 'fraction_numerical': 0.01920637796702301, 'mean_word_length': 2.6726546906187623, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 11, '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': '295770', 'n_tokens_mistral': 1743, 'n_tokens_neox': 1639, 'n_words': 335}