Ejemplo n.º 1
0
from models.curriculum import (
        Curriculum,
        LO_list_to_dict,
        dict_to_LO_list,
        dump_LO_dict
        )

""" Scripts which builds a curriculum for the user from an input
learning outcome .txt file and dumps it to a pickle file.
A human-readable version is dumped to a json file, as a dictionary """

# Instantiates a curriculum object
curr = Curriculum()
# User inputs name of the curriculum e.g. 'computer_science'
curr.user_input_name()
# User inputs name of the .txt file containing the learning outcomes
curr.user_input_filename_LOs()
# Sets the number of learning outcome strands from blank lines in file
curr.set_num_strands_from_file()
# Checks with user whether number of strands is correct
curr.user_check_num_strands()
# User inputs names of the strands
curr.user_input_strand_names()
# Loads the LOs into the curriculum, as a list of lists of LearningOutcome objects
curr.load_LOs_from_file(curr.filename_LOs_txt)
# Writes a pickle object representation of the curriculum to file
curr.dump_curriculum(f"{curr.name}.curriculum.pickle")
# Converts the LO lists to dictionary form
LO_dict = LO_list_to_dict(curr.LOs, curr.strand_names)
dump_LO_dict(LO_dict, f"{curr.name}.LO_dict.json")
class TestCurriculum(unittest.TestCase):
    def setUp(self):
        self.curr_1 = Curriculum(name="computer_science",
                                 country="ireland",
                                 ID="n/a",
                                 num_of_strands=3,
                                 strand_names=[
                                     "core concepts",
                                     "practices and principles",
                                     "applied learning tasks"
                                 ],
                                 filename_LOs_txt="./fixtures/test_LO_CS.txt")

    def tearDown(self):
        pass

    def test_init(self):
        self.assertEqual(self.curr_1.name, "COMPUTER_SCIENCE")
        self.assertEqual(self.curr_1.country, "Ireland")
        self.assertEqual(self.curr_1.ID, "n/a")
        self.assertEqual(self.curr_1.num_of_strands, 3)
        self.assertEqual(self.curr_1.strand_names[0], "CORE CONCEPTS")

    def test_set_num_of_strands(self):
        self.assertRaises(TypeError, self.curr_1.set_num_of_strands, 2.5)
        self.assertRaises(TypeError, self.curr_1.set_num_of_strands, "igs")

    def test_set_num_strands_from_file(self):
        self.curr_1.set_num_of_strands(0)
        self.curr_1.set_num_strands_from_file(self.curr_1.filename_LOs_txt)
        self.assertEqual(self.curr_1.num_of_strands, 3)

    def test_add_strand_name(self):
        self.curr_1.add_strand_name("dummy")
        self.assertEqual(len(self.curr_1.strand_names), 4)
        self.assertEqual(self.curr_1.add_strand_name("dummy"), False)
        self.assertEqual(len(self.curr_1.strand_names), 4)

    def test_add_strand_names(self):
        self.curr_1.add_strand_names(["dummy", "dummy_2"])
        self.assertEqual(len(self.curr_1.strand_names), 5)
        self.curr_1.add_strand_names(["dummy", "dummy_2"])
        self.assertEqual(len(self.curr_1.strand_names), 5)

    def test_load_LOs_from_file(self):
        self.curr_1.load_LOs_from_file(self.curr_1.filename_LOs_txt)
        self.assertEqual([len(self.curr_1.LOs[i]) for i in range(3)],
                         [23, 22, 14])
        self.assertEqual(
            self.curr_1.LOs[1][-1].text,
            "students can explain the different stages in software testing")
        self.assertEqual(
            self.curr_1.LOs[2][-2].text,
            "students can develop a program that utilises digital and analogue inputs"
        )

    def test_list_to_dict_conversion(self):
        """ This simulataneously tests LO_list_to_dict and dict_to_LO_list (inverse functions) """
        self.curr_1.load_LOs_from_file(self.curr_1.filename_LOs_txt)
        LO_dict = LO_list_to_dict(self.curr_1.LOs, self.curr_1.strand_names)
        LO_list = dict_to_LO_list(LO_dict)
        LO_dict_2 = LO_list_to_dict(LO_list, self.curr_1.strand_names)
        self.assertEqual(LO_dict, LO_dict_2)

    def test_getitem(self):
        self.curr_1.load_LOs_from_file(self.curr_1.filename_LOs_txt)
        dict_1, i = {}, 0
        for strand in self.curr_1.LOs:
            for LO in strand:
                dict_1[i] = LO.text
                i += 1
        dict_2 = {i: LO.text for i, LO in enumerate(self.curr_1)}
        self.assertEqual(dict_1, dict_2)