Beispiel #1
0
def test_parameter_delivery_default_exam(tmp_path, empty_contents,
                                         setup_in_home, simple_exam_csv_file,
                                         monkeypatch):
    """GIVEN a configuration ini file
    WHEN to_pdf is called
    THEN Exam.print_exam is called with default destination exam file as argument
    AND pdf section as keyword argument
    """
    class MonkeyWin(p66.ContentMix):  # monkey info window
        def infobox(self, title, text):
            pass

    class Monkey:
        args = tuple()
        kwargs = {}

        def print_exam(self, *args, **kwargs):
            Monkey.args = args
            Monkey.kwargs = kwargs
            pass

        def print_checker(self, *args, **kwargs):
            pass

    monkeypatch.setattr(p66, "ContentMix", MonkeyWin)
    monkeypatch.setattr(exam2pdf.Exam, "print_exam", Monkey.print_exam)
    monkeypatch.setattr(exam2pdf.Exam, "print_checker", Monkey.print_checker)

    cont = p66.ContentMix()
    cont.to_pdf(simple_exam_csv_file, tmp_path)

    assert Monkey.args[0] == tmp_path / p66.EXAM_PDF_FILE
    assert Monkey.kwargs == empty_contents["pdf_exam"]
Beispiel #2
0
def test_parameter_delivery_additional(
    tmp_path,
    additional_contents,
    setup_in_home_with_additional,
    simple_exam_csv_file,
    monkeypatch,
):
    """GIVEN a configuration ini file
    WHEN to_pdf is called
    THEN Exam.print_exam is called additional parameter are managed
    """
    class MonkeyWin(p66.ContentMix):  # monkey info window
        def infobox(self, title, text):
            pass

    class MonkeyExam:
        def from_csv(self, *args, **kwargs):
            pass

        def print_exam(self, *args, **kwargs):
            pass

        def print_checker(self, *args, **kwargs):
            pass

    monkeypatch.setattr(p66, "ContentMix", MonkeyWin)
    monkeypatch.setattr(exam2pdf, "Exam", MonkeyExam)

    cont = p66.ContentMix()
    cont.to_pdf(simple_exam_csv_file, tmp_path)

    assert MonkeyExam.load_sequence == ["third", "second", "first"]
Beispiel #3
0
def test_contentmix_parameter(empty_contents, setup_in_current):
    """GIVEN ContentMix call with conf.ini
    THEN parameters are set
    """
    file_path = pathlib.Path("conf.ini")

    cont = p66.ContentMix(file_path)

    assert cont.parameters == empty_contents
Beispiel #4
0
def test_contentmix_no_cvs_file(tmp_path, monkeypatch):
    """GIVEN a cvs file
    WHEN the given file is not found
    THEN Exam2pdf exception is raised
    """
    class MonkeyWin(p66.ContentMix):
        def errorbox(self, _):
            pass

        def infobox(self, title, text):
            pass

    monkeypatch.setattr(p66, "ContentMix", MonkeyWin)

    cont = p66.ContentMix()
    with pytest.raises(exam2pdf.Exam2pdfException):
        cont.to_pdf(tmp_path / "no_file", tmp_path)
Beispiel #5
0
def test_contentmix_cvs_image_not_found(tmp_path, setup_dirs,
                                        exam_with_wrong_picture, monkeypatch):
    """GIVEN a cvs file
    WHEN an image path is not found
    THEN Exam2pdf exception is raised
    """
    class MonkeyWin(p66.ContentMix):
        def errorbox(self, _):
            pass

        def infobox(self, title, text):
            pass

    monkeypatch.setattr(p66, "ContentMix", MonkeyWin)

    cont = p66.ContentMix()
    with pytest.raises(exam2pdf.Exam2pdfException):
        cont.to_pdf(exam_with_wrong_picture, tmp_path)
Beispiel #6
0
def test_parameter_delivery_exam(
    tmp_path,
    filename_contents,
    setup_in_current_with_name,
    simple_exam_csv_file,
    monkeypatch,
):
    """GIVEN a configuration ini file
    WHEN to_pdf is called
    THEN Exam.print_exam is called with destination exam file as argument
    AND pdf section as keyword argument with n_copies correctly casted
    """
    class MonkeyWin(p66.ContentMix):  # monkey info window
        def infobox(self, title, text):
            pass

    class Monkey:
        args = tuple()
        kwargs = {}

        def print(self, *args, **kwargs):
            Monkey.args = args
            Monkey.kwargs = kwargs
            pass

        def print_checker(self, *args, **kwargs):
            pass

    monkeypatch.setattr(p66, "ContentMix", MonkeyWin)
    monkeypatch.setattr(exam2pdf.Exam, "print_exam", Monkey.print)
    monkeypatch.setattr(exam2pdf.Exam, "print_checker", Monkey.print_checker)

    cont = p66.ContentMix()
    cont.to_pdf(simple_exam_csv_file, tmp_path)

    assert Monkey.args[0] == tmp_path / "exam_file_name.pdf"

    del filename_contents["pdf_exam"]["exam_file_name"]
    del filename_contents["pdf_exam"]["questions_shuffle"]
    assert Monkey.kwargs == filename_contents["pdf_exam"]
Beispiel #7
0
def test_parameter_delivery_csv(tmp_path, empty_contents, setup_in_home,
                                simple_exam_csv_file, monkeypatch):
    """GIVEN a configuration ini file
    WHEN to_pdf is called
    THEN Exam.from_csv is called with csv source file as argument
    AND dictreader section as keyword argument
    """
    class MonkeyWin(p66.ContentMix):  # monkey info window
        def infobox(self, title, text, *args):
            pass

    class Monkey:
        args = tuple()
        kwargs = {}

        def from_csv(self, *args, **kwargs):
            Monkey.args = args
            Monkey.kwargs = kwargs
            pass

        def print(self, *args, **kwargs):
            pass

        def print_checker(self, *args, **kwargs):
            pass

    monkeypatch.setattr(p66, "ContentMix", MonkeyWin)
    monkeypatch.setattr(exam2pdf.Exam, "print_exam", Monkey.print)
    monkeypatch.setattr(exam2pdf.Exam, "print_checker", Monkey.print_checker)
    monkeypatch.setattr(exam2pdf.Exam, "from_csv", Monkey.from_csv)

    cont = p66.ContentMix()
    cont.to_pdf(simple_exam_csv_file, tmp_path)

    assert Monkey.args[0] == tmp_path / simple_exam_csv_file
    assert Monkey.kwargs == empty_contents["DictReader"]
Beispiel #8
0
def test_contentmix_no_ini_file():
    """GIVEN ContentMix call without argument
    THEN no exception is raised
    """
    p66.ContentMix()
    assert True