Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repos:
- id: check-added-large-files
args: [--maxkb=6000]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.6
rev: v0.11.4
hooks:
# Ruff fix
- id: ruff
Expand All @@ -23,7 +23,7 @@ repos:
types_or: [python, pyi]
name: ruff (format)
- repo: https://github.com/google/yamlfmt
rev: v0.14.0
rev: v0.16.0
hooks:
- id: yamlfmt
name: YAML (format)
Expand Down
2 changes: 1 addition & 1 deletion tutorial/tests/test_basic_datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ def test_update_one_dict_with_another(my_dict1, my_dict2, function_to_test):
"ab",
"abc",
"abcd",
"a b c d e" "One two three four five six seven eight nine ten",
"a b c d eOne two three four five six seven eight nine ten",
"Hello world",
"How are you?",
]
Expand Down
18 changes: 9 additions & 9 deletions tutorial/tests/test_control_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ def reference_range_of_nums(start: int, end: int) -> List[int]:
],
)
def test_range_of_nums(start: int, end: int, function_to_test) -> None:
assert reference_range_of_nums(start, end) == function_to_test(
start, end
), "The function returned an empty range"
assert reference_range_of_nums(start, end) == function_to_test(start, end), (
"The function returned an empty range"
)


def reference_sqrt_of_nums(numbers: List[int]) -> List[float]:
Expand Down Expand Up @@ -101,12 +101,12 @@ def reference_sqrt_of_nums(numbers: List[int]) -> List[float]:
def test_sqrt_of_nums(nums: list[int], function_to_test) -> None:
reference, result = reference_sqrt_of_nums(nums), function_to_test(nums)
assert isinstance(result, list), "The function should return a list, not 'None'"
assert len(reference) == len(
result
), "The function should return a list of the same length"
assert all(
isclose(x, y) for x, y in zip(reference, result)
), "The function should return the square root of each number"
assert len(reference) == len(result), (
"The function should return a list of the same length"
)
assert all(isclose(x, y) for x, y in zip(reference, result)), (
"The function should return the square root of each number"
)


def reference_divide_until(number: int) -> int:
Expand Down
24 changes: 12 additions & 12 deletions tutorial/tests/test_functional_programming.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ def reference_filter_even(my_list: List[int]) -> List[int]:
def test_filter_even(function_to_test: Callable, my_list: List[int]):
res = function_to_test(my_list)
assert isinstance(res, list), "The function you wrote does not return a list"
assert res == reference_filter_even(
my_list
), "The list you return is not equal to the expected solution"
assert not check_for_loop_in_body(
function_to_test
), "You are not allowed to use a for loop in this exercise"
assert res == reference_filter_even(my_list), (
"The list you return is not equal to the expected solution"
)
assert not check_for_loop_in_body(function_to_test), (
"You are not allowed to use a for loop in this exercise"
)


def reference_add_one(my_list: List[int]) -> List[int]:
Expand All @@ -60,12 +60,12 @@ def reference_add_one(my_list: List[int]) -> List[int]:
],
)
def test_add_one(function_to_test: Callable, my_list: List[int]):
assert function_to_test(my_list) == reference_add_one(
my_list
), "The list you return is not equal to the expected solution"
assert not check_for_loop_in_body(
function_to_test
), "You are not allowed to use a for loop in this exercise"
assert function_to_test(my_list) == reference_add_one(my_list), (
"The list you return is not equal to the expected solution"
)
assert not check_for_loop_in_body(function_to_test), (
"You are not allowed to use a for loop in this exercise"
)


@pytest.mark.parametrize(
Expand Down
108 changes: 54 additions & 54 deletions tutorial/tests/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,19 @@ def test_greet(

# Check number and names of parameters
assert len(params) == 2, "The function should take two arguments."
assert (
"name" in params and "age" in params
), "The function's parameters should be 'name' and 'age'."
assert "name" in params and "age" in params, (
"The function's parameters should be 'name' and 'age'."
)

# Check type hints for parameters
assert all(
p.annotation != inspect.Parameter.empty for p in params.values()
), "The function's parameters should have type hints."
assert all(p.annotation != inspect.Parameter.empty for p in params.values()), (
"The function's parameters should have type hints."
)

# Check return type hint
assert (
return_annotation != inspect.Signature.empty
), "The function's return value is missing the type hint."
assert return_annotation != inspect.Signature.empty, (
"The function's return value is missing the type hint."
)

# Test the return value
assert function_to_test(name, age) == reference_greet(name, age)
Expand All @@ -80,15 +80,15 @@ def validate_basic_area_signature(function_to_test) -> None:
return_annotation = signature.return_annotation

assert function_to_test.__doc__ is not None, "The function is missing a docstring."
assert (
len(params) == 2
), "The function should take exactly two arguments (length and width)."
assert all(
p in params.keys() for p in ["length", "width"]
), "The function's parameters should be 'length' and 'width'."
assert all(
p.annotation is float for p in params.values()
), "Both parameters should be annotated as float."
assert len(params) == 2, (
"The function should take exactly two arguments (length and width)."
)
assert all(p in params.keys() for p in ["length", "width"]), (
"The function's parameters should be 'length' and 'width'."
)
assert all(p.annotation is float for p in params.values()), (
"Both parameters should be annotated as float."
)
assert return_annotation is str, "The return type should be annotated as str."


Expand Down Expand Up @@ -134,24 +134,24 @@ def validate_metric_area_signature(function_to_test) -> None:
return_annotation = signature.return_annotation

assert function_to_test.__doc__ is not None, "The function is missing a docstring."
assert (
len(params) == 3
), "The function should take three arguments (length, width, and unit)."
assert all(
p in params.keys() for p in ["length", "width", "unit"]
), "The function's parameters should be 'length', 'width' and 'unit'."
assert (
params["length"].annotation is float
), "Parameter 'length' should be annotated as float."
assert (
params["width"].annotation is float
), "Parameter 'width' should be annotated as float."
assert (
params["unit"].annotation is str
), "Parameter 'unit' should be annotated as str."
assert (
params["unit"].default == "cm"
), "Parameter 'unit' should have a default value of 'cm'."
assert len(params) == 3, (
"The function should take three arguments (length, width, and unit)."
)
assert all(p in params.keys() for p in ["length", "width", "unit"]), (
"The function's parameters should be 'length', 'width' and 'unit'."
)
assert params["length"].annotation is float, (
"Parameter 'length' should be annotated as float."
)
assert params["width"].annotation is float, (
"Parameter 'width' should be annotated as float."
)
assert params["unit"].annotation is str, (
"Parameter 'unit' should be annotated as str."
)
assert params["unit"].default == "cm", (
"Parameter 'unit' should have a default value of 'cm'."
)
assert return_annotation is str, "The return type should be annotated as str."


Expand Down Expand Up @@ -195,24 +195,24 @@ def validate_area_signature(function_to_test) -> None:
return_annotation = signature.return_annotation

assert function_to_test.__doc__ is not None, "The function is missing a docstring."
assert (
len(params) == 3
), "The function should take three arguments (length, width, and unit)."
assert all(
p in params.keys() for p in ["length", "width", "unit"]
), "The function's parameters should be 'length', 'width' and 'unit'."
assert (
params["length"].annotation is float
), "Parameter 'length' should be annotated as float."
assert (
params["width"].annotation is float
), "Parameter 'width' should be annotated as float."
assert (
params["unit"].annotation is str
), "Parameter 'unit' should be annotated as str."
assert (
params["unit"].default == "cm"
), "Parameter 'unit' should have a default value of 'cm'."
assert len(params) == 3, (
"The function should take three arguments (length, width, and unit)."
)
assert all(p in params.keys() for p in ["length", "width", "unit"]), (
"The function's parameters should be 'length', 'width' and 'unit'."
)
assert params["length"].annotation is float, (
"Parameter 'length' should be annotated as float."
)
assert params["width"].annotation is float, (
"Parameter 'width' should be annotated as float."
)
assert params["unit"].annotation is str, (
"Parameter 'unit' should be annotated as str."
)
assert params["unit"].default == "cm", (
"Parameter 'unit' should have a default value of 'cm'."
)
assert return_annotation is str, "The return type should be annotated as str."


Expand Down
10 changes: 6 additions & 4 deletions tutorial/tests/test_input_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,13 @@ def test_write_file(function_to_test, tmp_path: pl.Path):
function_to_test(tmp_user)
reference_write_file(tmp_test)

assert tmp_user.exists(), """The file was not created. Make sure to create the file in the function. Hint: use `open(output_file, "w")`"""
assert tmp_user.exists(), (
"""The file was not created. Make sure to create the file in the function. Hint: use `open(output_file, "w")`"""
)

assert (
tmp_user.read_text() == tmp_test.read_text()
), "The file content is not correct."
assert tmp_user.read_text() == tmp_test.read_text(), (
"The file content is not correct."
)


def reference_read_write_file(input_file: pl.Path, output_file: pl.Path) -> None:
Expand Down
Loading