Skip to content

Commit

Permalink
TDD Pandas - Create fixture from repeated input data
Browse files Browse the repository at this point in the history
  • Loading branch information
diligejy committed Jan 20, 2024
1 parent fd4d58c commit e7e08f8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 24 deletions.
3 changes: 2 additions & 1 deletion PyCon_PL/Readme.md
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)
32 changes: 9 additions & 23 deletions PyCon_PL/Test_Driven_Pandas/tests/test_gradebook.py
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:
Expand Down Expand Up @@ -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,
Expand All @@ -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]',
Expand Down

0 comments on commit e7e08f8

Please sign in to comment.