示例#1
0
def test_shuffle_from_csv(tmp_path):
    data_file = tmp_path / "data.csv"
    save_mono_question_data(data_file)

    data = CSVReader(str(data_file))
    rows = data.to_dictlist()

    exam = Exam()
    exam.attribute_selector = (
        "question",
        "subject",
        "image",
        "void",
        "A",
        "void",
        "B",
        "void",
        "C",
        "void",
        "D",
        "void",
    )

    exam.load(rows)
    exam.add_path_parent(data_file)
    random.seed(1)
    exam.shuffle()

    for question in exam.questions:
        assert question.correct_answer.text == "a"
    assert exam.questions[0]._answers[0].text == "d"
    assert exam.questions[1]._answers[0].text == "d"
示例#2
0
    def to_pdf(self, input_file: Path, output_folder: Path):
        rows = self._get_rows(input_file)

        if not rows:
            LOGGER.warning("Empty rows.")
            self.errorbox("Invalid data")
            return

        try:
            exam = Exam()
            exam.attribute_selector = (
                "question",
                "subject",
                "image",
                "void",
                "A",
                "void",
                "B",
                "void",
                "C",
                "void",
                "D",
                "void",
            )
            exam.load(rows)
            exam.add_path_parent(input_file)
            serial_exam = SerializeExam(exam)
            for number in range(int(self.parameters["number"])):
                if self.parameters["not_shuffle"] is False:
                    exam.shuffle()
                output_file_name_exam = Path(f"{self.parameters['exam']}_{number}.pdf")

                if self.parameters["page_heading"] != "":
                    exam_heading = f"{self.parameters['page_heading']} file n. {number}"
                else:
                    exam_heading = ""

                exam_footer = self.parameters["page_footer"]

                to_pdf_interface = RLInterface(
                    serial_exam.assignment(),
                    output_file_name_exam,
                    destination=output_folder,
                    heading=exam_heading,
                    footer=exam_footer,
                )
                to_pdf_interface.build()
                output_file_name_correction = Path(
                    f"{self.parameters['correction']}_{number}.pdf"
                )
                to_pdf_interface = RLInterface(
                    serial_exam.correction(),
                    output_file_name_correction,
                    destination=output_folder,
                    top_item_bullet_type="A",
                    sub_item_bullet_type="1",
                    heading=output_file_name_exam.name,
                )
                to_pdf_interface.build()
        except Exception as err:
            LOGGER.critical("CSVReader failed: %s %s", err.__class__, err)
            self.errorbox(exception_printer(err))
            raise
        self.infobox("Avviso", "Conversione effettuata")

        self.data_queue.put("end")