Skip to content

Commit

Permalink
Implemete clean_data functions and update README
Browse files Browse the repository at this point in the history
  • Loading branch information
beccaelenzil committed Feb 11, 2022
1 parent 7112b64 commit 9f64e6e
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 42 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,12 @@ python3 play_tester.py

There is some starter code provided in `play_tester.py`. This code prints the test data that is used for many of the tests. Looking closely at this data can help us think critically about the expected output for given input for each function. Then, calling each function with this data allows us to observe the **actual** output for given input.

## Test Data

We will note that much of the test data for this project is provided by the file `test_constants.py`. As test data gets more and more complex, it is helpful to organize this data in its own file to enhance consistency and readability. Pytest, like many testing libraries, provide a special too for test data called **fixtures**. We will learn about fixtures later in the curriculum.

For the time being, we need to make sure that the data provided to each test is clean and free of any changes that running another test may have introduced. Recall modifying mutable objects section of the [Variables Are References](https://learn-2.galvanize.com/cohorts/2330/blocks/1829/content_files/variables-and-memory/variables-are-references.md#modifying-mutable-objects) lesson. To ensure that the data for each test is storied in a unique place in memory, there are functions implemented in `test_constants.py` that provide clean test data (i.e. `clean_wave_3_data`) by using `copy.deepcopy`.

## Project Directions

This project is designed such that one could puzzle together how to implement this project without many directions. Being able to read tests to understand what is expected of our program is a skill that needs to be developed; programmers often take years to develop this skill competently.
Expand Down
18 changes: 11 additions & 7 deletions play_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,24 @@

# import "pretty-print" library
import pprint

# use library to print data structures in a nicely formatted way
pp = pprint.PrettyPrinter(indent=4)

print("\n-----Wave 02 user_data-----")
pp.pprint(USER_DATA_2)
# play testing section
print("\n-----Wave 01 test data-----")
pp.pprint(HORROR_1)
pp.pprint(FANTASY_1)
pp.pprint(FANTASY_2)

# print("\n-----Wave 02 user_data-----")
# pp.pprint(clean_wave_2_data())

#print("\n-----Wave 03 user_data-----")
#pp.pprint(USER_DATA_3)
#pp.pprint(clean_wave_3_data())

# Wave 04 user data
#print("\n-----Wave 04 user_data-----")
#pp.pprint(USER_DATA_4)
#pp.pprint(clean_wave_4_data())

# Wave 05 user data
#print("\n-----Wave 05 user_data-----")
#pp.pprint(USER_DATA_5)
#pp.pprint(clean_wave_5_data())
16 changes: 15 additions & 1 deletion tests/test_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,18 @@
FANTASY_2b,
INTRIGUE_1b,
INTRIGUE_2b
]
]

#----Functions that return clean data for each test----

def clean_wave_2_data():
return copy.deepcopy(USER_DATA_2)

def clean_wave_3_data():
return copy.deepcopy(USER_DATA_3)

def clean_wave_4_data():
return copy.deepcopy(USER_DATA_4)

def clean_wave_5_data():
return copy.deepcopy(USER_DATA_5)
86 changes: 77 additions & 9 deletions tests/test_wave_02.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,59 @@
import pytest
from viewing_party.party import *
from tests.test_constants import USER_DATA_2
import copy

@pytest.mark.skip()
def test_calculates_watched_average_rating():
# Arrange
janes_data = USER_DATA_2
janes_data = {
'watched': [
{
'title': 'The Lord of the Functions: The Fellowship of the Function',
'genre': 'Fantasy',
'rating': 4.8
},
{
'title': 'The Lord of the Functions: The Two Parameters',
'genre': 'Fantasy',
'rating': 4.0
},
{
'title': 'The Lord of the Functions: The Return of the Value',
'genre': 'Fantasy',
'rating': 4.0
},
{
'title': 'The JavaScript and the React',
'genre': 'Action',
'rating': 2.2
},
{
'title': 'Recursion',
'genre': 'Intrigue',
'rating': 2.0
},
{
'title': 'Instructor Student TA Manager',
'genre': 'Intrigue',
'rating': 4.5
}
]
}

janes_data_before = copy.deepcopy(janes_data)

# Act
average = get_watched_avg_rating(janes_data)

# Assert
assert average == pytest.approx(3.58333)
assert janes_data is USER_DATA_2
assert janes_data == janes_data_before

@pytest.mark.skip()
def test_empty_watched_average_rating_is_zero():
# Arrange
janes_data = {
"watched": [
]
"watched": []
}

# Act
Expand All @@ -31,14 +65,48 @@ def test_empty_watched_average_rating_is_zero():
@pytest.mark.skip()
def test_most_watched_genre():
# Arrange
janes_data = USER_DATA_2
janes_data = {
'watched': [
{
'title': 'The Lord of the Functions: The Fellowship of the Function',
'genre': 'Fantasy',
'rating': 4.8
},
{
'title': 'The Lord of the Functions: The Two Parameters',
'genre': 'Fantasy',
'rating': 4.0
},
{
'title': 'The Lord of the Functions: The Return of the Value',
'genre': 'Fantasy',
'rating': 4.0
},
{
'title': 'The JavaScript and the React',
'genre': 'Action',
'rating': 2.2
},
{
'title': 'Recursion',
'genre': 'Intrigue',
'rating': 2.0
},
{
'title': 'Instructor Student TA Manager',
'genre': 'Intrigue',
'rating': 4.5
}
]
}
janes_data_before = copy.deepcopy(janes_data)

# Act
popular_genre = get_most_watched_genre(janes_data)

# Assert
assert popular_genre is "Fantasy"
assert janes_data is USER_DATA_2
assert popular_genre == "Fantasy"
assert janes_data == janes_data_before

@pytest.mark.skip()
def test_genre_is_None_if_empty_watched():
Expand All @@ -51,4 +119,4 @@ def test_genre_is_None_if_empty_watched():
popular_genre = get_most_watched_genre(janes_data)

# Assert
assert popular_genre is None
assert popular_genre == None
22 changes: 11 additions & 11 deletions tests/test_wave_03.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,55 +5,55 @@
@pytest.mark.skip()
def test_my_unique_movies():
# Arrange
amandas_data = USER_DATA_3
amandas_data = clean_wave_3_data()

# Act
amandas_unique_movies = get_unique_watched(amandas_data)

# Arrange
assert len(amandas_unique_movies) is 2
assert len(amandas_unique_movies) == 2
assert FANTASY_2 in amandas_unique_movies
assert INTRIGUE_2 in amandas_unique_movies
assert amandas_data is USER_DATA_3
assert amandas_data == clean_wave_3_data()

@pytest.mark.skip()
def test_my_not_unique_movies():
# Arrange
amandas_data = copy.deepcopy(USER_DATA_3)
amandas_data = clean_wave_3_data()
amandas_data["watched"] = []

# Act
amandas_unique_movies = get_unique_watched(amandas_data)

# Arrange
assert len(amandas_unique_movies) is 0
assert len(amandas_unique_movies) == 0

@pytest.mark.skip()
def test_friends_unique_movies():
# Arrange
amandas_data = USER_DATA_3
amandas_data = clean_wave_3_data()

# Act
friends_unique_movies = get_friends_unique_watched(amandas_data)

# Arrange
assert len(friends_unique_movies) is 3
assert len(friends_unique_movies) == 3
assert INTRIGUE_3 in friends_unique_movies
assert HORROR_1 in friends_unique_movies
assert FANTASY_4 in friends_unique_movies
assert amandas_data is USER_DATA_3
assert amandas_data == clean_wave_3_data()

@pytest.mark.skip()
def test_friends_unique_movies_not_duplicated():
# Arrange
amandas_data = copy.deepcopy(USER_DATA_3)
amandas_data = clean_wave_3_data()
amandas_data["friends"][0]["watched"].append(INTRIGUE_3)

# Act
friends_unique_movies = get_friends_unique_watched(amandas_data)

# Arrange
assert len(friends_unique_movies) is 3
assert len(friends_unique_movies) == 3
assert INTRIGUE_3 in friends_unique_movies
assert HORROR_1 in friends_unique_movies
assert FANTASY_4 in friends_unique_movies
Expand Down Expand Up @@ -84,4 +84,4 @@ def test_friends_not_unique_movies():
friends_unique_movies = get_friends_unique_watched(amandas_data)

# Arrange
assert len(friends_unique_movies) is 0
assert len(friends_unique_movies) == 0
8 changes: 4 additions & 4 deletions tests/test_wave_04.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
@pytest.mark.skip()
def test_get_available_friend_rec():
# Arrange
amandas_data = USER_DATA_4
amandas_data = clean_wave_4_data()

# Act
recommendations = get_available_recs(amandas_data)

# Arrange
assert len(recommendations) is 2
assert len(recommendations) == 2
assert HORROR_1b in recommendations
assert FANTASY_4b in recommendations
assert amandas_data is USER_DATA_4
assert amandas_data == clean_wave_4_data()

@pytest.mark.skip()
def test_no_available_friend_recs():
Expand All @@ -36,4 +36,4 @@ def test_no_available_friend_recs():
recommendations = get_available_recs(amandas_data)

# Arrange
assert len(recommendations) is 0
assert len(recommendations) == 0
20 changes: 10 additions & 10 deletions tests/test_wave_05.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
@pytest.mark.skip()
def test_new_genre_rec():
# Arrange
sonyas_data = USER_DATA_5
sonyas_data = clean_wave_5_data()

# Act
recommendations = get_new_rec_by_genre(sonyas_data)

# Assert
for rec in recommendations:
assert rec not in sonyas_data["watched"]
assert len(recommendations) is 1
assert len(recommendations) == 1
assert FANTASY_4b in recommendations
assert sonyas_data is USER_DATA_5
assert sonyas_data == clean_wave_5_data()

@pytest.mark.skip()
def test_new_genre_rec_from_empty_watched():
Expand All @@ -36,7 +36,7 @@ def test_new_genre_rec_from_empty_watched():
recommendations = get_new_rec_by_genre(sonyas_data)

# Assert
assert len(recommendations) is 0
assert len(recommendations) == 0

@pytest.mark.skip()
def test_new_genre_rec_from_empty_friends():
Expand All @@ -57,21 +57,21 @@ def test_new_genre_rec_from_empty_friends():
recommendations = get_new_rec_by_genre(sonyas_data)

# Assert
assert len(recommendations) is 0
assert len(recommendations) == 0

@pytest.mark.skip()
def test_unique_rec_from_favorites():
# Arrange
sonyas_data = USER_DATA_5
sonyas_data = clean_wave_5_data()

# Act
recommendations = get_rec_from_favorites(sonyas_data)

# Assert
assert len(recommendations) is 2
assert len(recommendations) == 2
assert FANTASY_2b in recommendations
assert INTRIGUE_2b in recommendations
assert sonyas_data is USER_DATA_5
assert sonyas_data == clean_wave_5_data()

@pytest.mark.skip()
def test_unique_from_empty_favorites():
Expand All @@ -92,7 +92,7 @@ def test_unique_from_empty_favorites():
recommendations = get_new_rec_by_genre(sonyas_data)

# Assert
assert len(recommendations) is 0
assert len(recommendations) == 0

@pytest.mark.skip()
def test_new_rec_from_empty_friends():
Expand All @@ -113,4 +113,4 @@ def test_new_rec_from_empty_friends():
recommendations = get_new_rec_by_genre(sonyas_data)

# Assert
assert len(recommendations) is 0
assert len(recommendations) == 0

0 comments on commit 9f64e6e

Please sign in to comment.