mirror of https://github.com/eyhc1/rendercv.git
enhance tests
This commit is contained in:
parent
b6c7e89041
commit
c0c936f670
|
@ -0,0 +1,63 @@
|
||||||
|
import pathlib
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def publication_entry() -> dict[str, str | list[str]]:
|
||||||
|
return {
|
||||||
|
"title": "My Title",
|
||||||
|
"authors": ["John Doe", "Jane Doe"],
|
||||||
|
"doi": "10.1109/TASC.2023.3340648",
|
||||||
|
"date": "2023-12-08",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def experience_entry() -> dict[str, str]:
|
||||||
|
return {
|
||||||
|
"company": "CERN",
|
||||||
|
"position": "Researcher",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def education_entry() -> dict[str, str]:
|
||||||
|
return {
|
||||||
|
"institution": "Boğaziçi University",
|
||||||
|
"area": "Mechanical Engineering",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def normal_entry() -> dict[str, str]:
|
||||||
|
return {
|
||||||
|
"name": "My Entry",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def one_line_entry() -> dict[str, str]:
|
||||||
|
return {
|
||||||
|
"name": "My One Line Entry",
|
||||||
|
"details": "My Details",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def text_entry() -> str:
|
||||||
|
return "My Text Entry"
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def tests_directory_path() -> pathlib.Path:
|
||||||
|
return pathlib.Path(__file__).parent
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def root_directory_path(tests_directory_path) -> pathlib.Path:
|
||||||
|
return tests_directory_path.parent
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def input_file_path(tests_directory_path) -> pathlib.Path:
|
||||||
|
return tests_directory_path / "input_files" / "John_Doe_CV.yaml"
|
|
@ -1,5 +1,4 @@
|
||||||
from datetime import date as Date
|
from datetime import date as Date
|
||||||
import pathlib
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
import pydantic
|
import pydantic
|
||||||
|
@ -9,67 +8,6 @@ import time_machine
|
||||||
from rendercv import data_models as dm
|
from rendercv import data_models as dm
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def publication_entry() -> dict[str, str | list[str]]:
|
|
||||||
return {
|
|
||||||
"title": "My Title",
|
|
||||||
"authors": ["John Doe", "Jane Doe"],
|
|
||||||
"doi": "10.1109/TASC.2023.3340648",
|
|
||||||
"date": "2023-12-08",
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def experience_entry() -> dict[str, str]:
|
|
||||||
return {
|
|
||||||
"company": "CERN",
|
|
||||||
"position": "Researcher",
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def education_entry() -> dict[str, str]:
|
|
||||||
return {
|
|
||||||
"institution": "Boğaziçi University",
|
|
||||||
"area": "Mechanical Engineering",
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def normal_entry() -> dict[str, str]:
|
|
||||||
return {
|
|
||||||
"name": "My Entry",
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def one_line_entry() -> dict[str, str]:
|
|
||||||
return {
|
|
||||||
"name": "My One Line Entry",
|
|
||||||
"details": "My Details",
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def text_entry() -> str:
|
|
||||||
return "My Text Entry"
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def tests_directory_path() -> pathlib.Path:
|
|
||||||
return pathlib.Path(__file__).parent
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def root_directory_path(tests_directory_path) -> pathlib.Path:
|
|
||||||
return tests_directory_path.parent
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def input_file_path(tests_directory_path) -> pathlib.Path:
|
|
||||||
return tests_directory_path / "input_files" / "John_Doe_CV.yaml"
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"date, expected_date_object, expected_error",
|
"date, expected_date_object, expected_error",
|
||||||
[
|
[
|
||||||
|
|
|
@ -0,0 +1,149 @@
|
||||||
|
import math
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
import jinja2
|
||||||
|
|
||||||
|
from rendercv import renderer as r
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"value, something, match_str, expected",
|
||||||
|
[
|
||||||
|
("Hello World", "textbf", None, "\\textbf{Hello World}"),
|
||||||
|
("Hello World", "textbf", "World", "Hello \\textbf{World}"),
|
||||||
|
("Hello World", "textbf", "Universe", "Hello World"),
|
||||||
|
("", "textbf", "Universe", ""),
|
||||||
|
("Hello World", "textbf", "", "Hello World"),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_make_matched_part_something(value, something, match_str, expected):
|
||||||
|
result = r.make_matched_part_something(value, something, match_str)
|
||||||
|
assert result == expected
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"value, match_str, expected",
|
||||||
|
[
|
||||||
|
("Hello World", None, "\\textbf{Hello World}"),
|
||||||
|
("Hello World", "World", "Hello \\textbf{World}"),
|
||||||
|
("Hello World", "Universe", "Hello World"),
|
||||||
|
("", "Universe", ""),
|
||||||
|
("Hello World", "", "Hello World"),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_make_matched_part_bold(value, match_str, expected):
|
||||||
|
result = r.make_matched_part_bold(value, match_str)
|
||||||
|
assert result == expected
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"value, match_str, expected",
|
||||||
|
[
|
||||||
|
("Hello World", None, "\\underline{Hello World}"),
|
||||||
|
("Hello World", "World", "Hello \\underline{World}"),
|
||||||
|
("Hello World", "Universe", "Hello World"),
|
||||||
|
("", "Universe", ""),
|
||||||
|
("Hello World", "", "Hello World"),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_make_matched_part_underlined(value, match_str, expected):
|
||||||
|
result = r.make_matched_part_underlined(value, match_str)
|
||||||
|
assert result == expected
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"value, match_str, expected",
|
||||||
|
[
|
||||||
|
("Hello World", None, "\\textit{Hello World}"),
|
||||||
|
("Hello World", "World", "Hello \\textit{World}"),
|
||||||
|
("Hello World", "Universe", "Hello World"),
|
||||||
|
("", "Universe", ""),
|
||||||
|
("Hello World", "", "Hello World"),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_make_matched_part_italic(value, match_str, expected):
|
||||||
|
result = r.make_matched_part_italic(value, match_str)
|
||||||
|
assert result == expected
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"value, match_str, expected",
|
||||||
|
[
|
||||||
|
("Hello World", None, "\\mbox{Hello World}"),
|
||||||
|
("Hello World", "World", "Hello \\mbox{World}"),
|
||||||
|
("Hello World", "Universe", "Hello World"),
|
||||||
|
("", "Universe", ""),
|
||||||
|
("Hello World", "", "Hello World"),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_make_matched_part_non_line_breakable(value, match_str, expected):
|
||||||
|
result = r.make_matched_part_non_line_breakable(value, match_str)
|
||||||
|
assert result == expected
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"name, expected",
|
||||||
|
[
|
||||||
|
("John Doe", "J. Doe"),
|
||||||
|
("John Jacob Jingleheimer Schmidt", "J. J. J. Schmidt"),
|
||||||
|
("SingleName", "SingleName"),
|
||||||
|
("", ""),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_abbreviate_name(name, expected):
|
||||||
|
result = r.abbreviate_name(name)
|
||||||
|
assert result == expected
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"length, divider, expected",
|
||||||
|
[
|
||||||
|
("10pt", 2, "5.0pt"),
|
||||||
|
("15cm", 3, "5.0cm"),
|
||||||
|
("20mm", 4, "5.0mm"),
|
||||||
|
("25ex", 5, "5.0ex"),
|
||||||
|
("30em", 6, "5.0em"),
|
||||||
|
("10pt", 3, "3.33pt"),
|
||||||
|
("10pt", 4, "2.5pt"),
|
||||||
|
("0pt", 1, "0.0pt"),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_divide_length_by(length, divider, expected):
|
||||||
|
result = r.divide_length_by(length, divider)
|
||||||
|
assert math.isclose(
|
||||||
|
float(result[:-2]), float(expected[:-2]), rel_tol=1e-2
|
||||||
|
), f"Expected {expected}, but got {result}"
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"length, divider",
|
||||||
|
[("10pt", 0), ("10pt", -1), ("invalid", 4)],
|
||||||
|
)
|
||||||
|
def test_invalid_divide_length_by(length, divider):
|
||||||
|
with pytest.raises(ValueError):
|
||||||
|
r.divide_length_by(length, divider)
|
||||||
|
|
||||||
|
|
||||||
|
def test_setup_jinja2_environment():
|
||||||
|
env = r.setup_jinja2_environment()
|
||||||
|
|
||||||
|
# Check if the returned object is a jinja2.Environment instance
|
||||||
|
assert isinstance(env, jinja2.Environment)
|
||||||
|
|
||||||
|
# Check if the custom delimiters are correctly set
|
||||||
|
assert env.block_start_string == "((*"
|
||||||
|
assert env.block_end_string == "*))"
|
||||||
|
assert env.variable_start_string == "<<"
|
||||||
|
assert env.variable_end_string == ">>"
|
||||||
|
assert env.comment_start_string == "((#"
|
||||||
|
assert env.comment_end_string == "#))"
|
||||||
|
|
||||||
|
# Check if the custom filters are correctly set
|
||||||
|
assert "make_it_bold" in env.filters
|
||||||
|
assert "make_it_underlined" in env.filters
|
||||||
|
assert "make_it_italic" in env.filters
|
||||||
|
assert "make_it_nolinebreak" in env.filters
|
||||||
|
assert "make_it_something" in env.filters
|
||||||
|
assert "divide_length_by" in env.filters
|
||||||
|
assert "abbreviate_name" in env.filters
|
||||||
|
|
Loading…
Reference in New Issue