|
5 | 5 | from ..exercises.exercise_ch8_01 import count_errors_from_file |
6 | 6 | from ..exercises.exercise_ch8_02 import count_word_frequency |
7 | 7 | from ..exercises.exercise_ch8_03 import course_grades_summary |
| 8 | +from ..exercises.exercise_ch8_04 import inventory_management |
8 | 9 |
|
9 | 10 | # from ..exercises.exercise_ch8_04 import FileHandler |
10 | 11 |
|
@@ -126,10 +127,101 @@ def test_ch08_e03(source, expected): |
126 | 127 | assert course_grades_summary(source) == expected |
127 | 128 |
|
128 | 129 |
|
129 | | -# TODO: Fix the exercise. |
130 | | -# def test_ch08_e04(source): |
131 | | -# file_handler = FileHandler(source) |
132 | | -# file_handler.write("Hello, World!") |
133 | | -# assert file_handler.read() == "Hello, World!" |
134 | | -# file_handler.close() |
135 | | -# assert file_handler.closed |
| 130 | +@pytest.mark.parametrize( |
| 131 | + "file_content, restock_threshold, expected", |
| 132 | + [ |
| 133 | + ( |
| 134 | + textwrap.dedent( |
| 135 | + """ |
| 136 | + """ |
| 137 | + ), |
| 138 | + 0, |
| 139 | + [], |
| 140 | + ), |
| 141 | + ( |
| 142 | + textwrap.dedent( |
| 143 | + """ |
| 144 | + item_name,item_id,quantity,price |
| 145 | + Apple,1,100,0.5 |
| 146 | + Banana,2,200,0.3 |
| 147 | + Orange,3,150,0.4 |
| 148 | + """ |
| 149 | + ), |
| 150 | + 200, |
| 151 | + [ |
| 152 | + { |
| 153 | + "item_name": "Apple", |
| 154 | + "item_id": 1, |
| 155 | + "quantity": 100, |
| 156 | + "price": 0.5, |
| 157 | + }, |
| 158 | + { |
| 159 | + "item_name": "Orange", |
| 160 | + "item_id": 3, |
| 161 | + "quantity": 150, |
| 162 | + "price": 0.4, |
| 163 | + }, |
| 164 | + ], |
| 165 | + ), |
| 166 | + ( |
| 167 | + textwrap.dedent( |
| 168 | + """ |
| 169 | + item_name,item_id,quantity,price |
| 170 | + Apple,1,100,0.5 |
| 171 | + Banana,2,200,0.3 |
| 172 | + Orange,3,150,0.4 |
| 173 | + """ |
| 174 | + ), |
| 175 | + 100, |
| 176 | + [ |
| 177 | + { |
| 178 | + "item_name": "Apple", |
| 179 | + "item_id": 1, |
| 180 | + "quantity": 100, |
| 181 | + "price": 0.5, |
| 182 | + }, |
| 183 | + ], |
| 184 | + ), |
| 185 | + ( |
| 186 | + textwrap.dedent( |
| 187 | + """ |
| 188 | + item_name,item_id,quantity,price |
| 189 | + Apple,1,100,0.5 |
| 190 | + Banana,2,200,0.3 |
| 191 | + Orange,3,150,0.4 |
| 192 | + """ |
| 193 | + ), |
| 194 | + 300, |
| 195 | + [], |
| 196 | + ), |
| 197 | + ( |
| 198 | + textwrap.dedent( |
| 199 | + """ |
| 200 | + item_name,item_id,quantity,price |
| 201 | + Apple,1,100,0.5 |
| 202 | + Banana,2,200,0.3 |
| 203 | + Orange,3,150,0.4 |
| 204 | + Pear,4,300,0.6 |
| 205 | + Kiwi,5,400,0.7 |
| 206 | + """ |
| 207 | + ), |
| 208 | + 250, |
| 209 | + [ |
| 210 | + { |
| 211 | + "item_name": "Apple", |
| 212 | + "item_id": 1, |
| 213 | + "quantity": 100, |
| 214 | + "price": 0.5, |
| 215 | + }, |
| 216 | + { |
| 217 | + "item_name": "Orange", |
| 218 | + "item_id": 3, |
| 219 | + "quantity": 150, |
| 220 | + "price": 0.4, |
| 221 | + }, |
| 222 | + ], |
| 223 | + ), |
| 224 | + ], |
| 225 | +) |
| 226 | +def test_ch08_e04(source, restock_threshold, expected): |
| 227 | + assert inventory_management(source, restock_threshold) == expected |
0 commit comments