You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+58-24
Original file line number
Diff line number
Diff line change
@@ -81,6 +81,8 @@ Summary of one-time project setup:
81
81
82
82
## Project Development Workflow
83
83
84
+
We will use a Test Driven Development programming workflow to work on this project. Notice the Red-Green-Refactor steps in the workflow steps outlined below.
85
+
84
86
1. When you want to begin work on this project, ensure that your virtual environment is activated:
85
87
86
88
```bash
@@ -89,54 +91,69 @@ $ source venv/bin/activate
89
91
90
92
2. Find the test file that contains the test you want to run. Ensure that the test(s) you want to run isn't skipped.
91
93
92
-
- Check the `tests` folder, and find the test file you want to run
94
+
- Check the `tests` folder, and find the test file you want to run
93
95
- In that test file, read through each test case
94
-
- Remove all lines that contain `@pytest.mark.skip()`
96
+
- If it is incomplete, complete the test.
97
+
-*Is this a nominal or edge case?*
98
+
-*What type of input do we need to test this case?*
99
+
-*What is the expected output for the given input?*
100
+
- Remove the lines that contain `@pytest.mark.skip()` for the test(s) you want to run.
95
101
96
-
3. Run the tests!
102
+
3. Run the test(s)! (RED)
103
+
-*See the [Details About How to Run Tests](#details-about-how-to-run-tests) section below for more information on how to run test(s).*
97
104
98
105
```bash
99
-
# Must be in activated virtual environment
106
+
# Must be in activated virtual environment in the project-root directory
100
107
$ pytest
101
108
```
102
109
103
-
4. Focus on the top test failure. Read through the test failure, and understand why the failure is happening. Confirm your findings with a classmate.
110
+
4. Focus on the top test failure. Read through the test failure, and understand why the failure is happening. Confirm your findings with a classmate.
111
+
- If it is a test you wrote, consider whether you are actually testing what you intend to test. Does the test need modification?
112
+
104
113
105
-
5. Make a plan to fix the test failure.
114
+
5. Make a plan to implement code to pass the test.
106
115
107
-
6. Write code to fix the test failure.
116
+
6. Write code in `party.py`to pass the test.
108
117
109
118
7. Re-run the tests.
110
119
111
-
8. Repeat steps 5-7 until that test passes!
120
+
8. Repeat steps 4-7 until that test passes! (GREEN)
112
121
113
-
9. Repeats steps 4-8 until you have finished all tests in the file.
122
+
9. Repeats steps 3-8 until you have finished all tests in the file.
114
123
115
-
10.Begin using the test file of the next wave!
124
+
10.Consider looking for opportunities to improve your code (REFACTOR)
116
125
117
-
11. When you are finished working for the day, deactivate your environment with deactivate or closing the Terminal tab/window
126
+
11. Begin using the test file of the next wave!
127
+
128
+
12. When you are finished working for the day, deactivate your environment with deactivate or closing the Terminal tab/window
118
129
119
130
```bash
120
131
$ deactivate
121
132
```
122
133
134
+
Finally, at submission time, **no matter where you are**, submit the project via Learn.
135
+
136
+
This will let us give feedback on what you've finished so that you can be better prepared for the next project.
137
+
123
138
## Details About How to Run Tests
124
139
125
-
Run all unskipped tests that exist in this project with:
140
+
All the commands described below should be run from the project-root directory `viewing-party`. Note that the project-root directory is the repository `viewing-party`. It is distinct from the directory `viewing_party` that contains the source code in `party.py`.
141
+
142
+
To run all unskipped tests that exist in this project with:
126
143
127
144
```bash
128
145
# Must be in activated virtual environment
129
146
$ pytest
130
147
```
131
148
132
-
If you want to see any `print` statements print to the console, add `-s` to the end of any `pytest` command:
149
+
To see any `print` statements print to the console, add `-s` to the end of any `pytest` command:
133
150
134
151
```bash
135
152
# Must be in activated virtual environment
136
153
$ pytest -s
137
154
```
138
155
139
-
If you want to run all unskipped tests that exist in one file, use:
156
+
To run all unskipped tests that exist in one file, use:
... where `test_file_name.py` is replaced with the correct test file name.
147
164
148
-
## Project Write-Up: How to Complete and Submit
165
+
To run a single test by name:
149
166
150
-
The goal of this project is to write code in `party.py` so that as many of the tests pass as possible.
167
+
```bash
168
+
# Must be in activated virtual environment
169
+
$ pytest tests/test_file_name.py::test_name
170
+
```
151
171
152
-
To complete this project, use the above workflow and follow these steps:
172
+
... where `test_name.py` is relpaced with the name of the function.
153
173
154
-
1. Start with making the tests in `test_wave_01.py` pass.
155
-
1. Review your code in `party.py` and see if there are ways you can make the code more readable.
156
-
1. Then, work on making the tests in `test_wave_02.py` pass.
157
-
1. Review your code in `party.py`
158
-
1. Repeat on all test files until submission time.
174
+
## Play Testing
159
175
160
-
At submission time, no matter where you are, submit the project via Learn.
176
+
While we will mainly use a Test Driven Development (TDD) workflow for this project, it can be helpful to run code independently from running tests. To do this, a file `play_tester.py` is provided.
177
+
178
+
To run this file, use:
179
+
180
+
```bash
181
+
# Must be in activated virtual environment in the project root-directory
182
+
python3 play_tester.py
183
+
```
184
+
185
+
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.
186
+
187
+
## Test Data
188
+
189
+
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.
190
+
191
+
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 the *Modifying Mutable Objects* section of the *Variables Are References 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`.
161
192
162
193
## Project Directions
163
194
@@ -178,7 +209,7 @@ In `party.py`, there should be a function named `create_movie`. This function sh
178
209
- The values of these key-value pairs should be appropriate values
179
210
- If `title` is falsy, `genre` is falsy, or `rating` is falsy, this function should return `None`
180
211
181
-
2. The next two tests are about an`add_to_watched()` function.
212
+
2. The next two tests are about the`add_to_watched()` function.
182
213
183
214
In `party.py`, there should be a function named `add_to_watched`. This function should...
184
215
@@ -230,6 +261,8 @@ In `party.py`, there should be a function named `watch_movie`. This function sho
230
261
- If the title isnot a movie in the user's watchlist:
231
262
-return the `user_data`
232
263
264
+
Note: For Waves 2, 3, 4, and5, your implementation of each of the functions should not modify `user_data`.
265
+
233
266
### Wave 2
234
267
235
268
1. The first two tests are about a `get_watched_avg_rating()` function.
@@ -253,6 +286,7 @@ In `party.py`, there should be a function named `get_most_watched_genre`. This f
253
286
- The values of `"genre"`is a string.
254
287
- Determine which genre is most frequently occurring in the watched list
255
288
-return the genre that is the most frequently watched
289
+
- If the value of "watched"is an empty list, `get_most_watched_genre` should return`None`.
0 commit comments