-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TDD Pandas - Create fixture from repeated input data
- Loading branch information
Showing
2 changed files
with
11 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
1. [Grzegorz Kocjan - Test Driven Pandas](https://youtu.be/oaADte_9u6Q) | ||
- [Folder](./Test_Driven_Pandas/) | ||
- [Link](https://belazy.dev/talks/test-driven-pandas/) | ||
- [Link](https://belazy.dev/talks/test-driven-pandas/) | ||
- [Pytest Fixture Ref](https://twpower.github.io/19-about-python-test-fixture) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import pandas as pd | ||
import pytest | ||
from typing import cast | ||
|
||
def _create_group(raw_students_group:pd.DataFrame) -> pd.DataFrame: | ||
|
@@ -45,8 +46,8 @@ def test_results_are_grouped_by_student_group_for_students_in_multiple_group(): | |
result = generate_gradebook(students_df=students_df) | ||
assert list(result.keys()) == [1, 2] | ||
|
||
def test_results_group_contains_students_net_id_lowercase(): | ||
@pytest.fixture | ||
def two_students_in_the_same_group() -> pd.DataFrame(): | ||
students = [ | ||
{ | ||
"ID": 1, | ||
|
@@ -63,32 +64,17 @@ def test_results_group_contains_students_net_id_lowercase(): | |
"Group": 1, | ||
}, | ||
] | ||
students_df = pd.DataFrame(data=students).set_index("ID") | ||
return pd.DataFrame(data=students).set_index("ID") | ||
|
||
result = generate_gradebook(students_df=students_df) | ||
def test_results_group_contains_students_net_id_lowercase(two_students_in_the_same_group): | ||
|
||
result = generate_gradebook(students_df=two_students_in_the_same_group) | ||
|
||
assert result[1]["net_id"].to_list() == ["jxd12345", "sxd54321"] | ||
|
||
def test_results_group_contains_students_email_address_lowercase(): | ||
students = [ | ||
{ | ||
"ID": 1, | ||
"Name": "Doe, John", | ||
"NetID": "JXD12345", | ||
"Email Address": "[email protected]", | ||
"Group": 1, | ||
}, | ||
{ | ||
"ID": 2, | ||
"Name": "Doe, Second", | ||
"NetID": "SXD54321", | ||
"Email Address": "[email protected]", | ||
"Group": 1, | ||
}, | ||
] | ||
students_df = pd.DataFrame(data=students).set_index("ID") | ||
def test_results_group_contains_students_email_address_lowercase(two_students_in_the_same_group): | ||
|
||
result = generate_gradebook(students_df = students_df) | ||
result = generate_gradebook(students_df = two_students_in_the_same_group) | ||
|
||
assert result[1]['email_address'].to_list() == [ | ||
'[email protected]', | ||
|