|
47 | 47 | },
|
48 | 48 | ]
|
49 | 49 |
|
| 50 | +now = datetime.datetime.now() |
50 | 51 | update_model_scenarios = [
|
51 | 52 | {
|
52 |
| - 'input_': model.Report(case='19-123456', date=datetime.datetime.now().date()), |
53 |
| - 'other': model.Report(case='19-123456', date=datetime.datetime.now().date()), |
54 |
| - 'expected': model.Report(case='19-123456', date=datetime.datetime.now().date()), |
55 |
| - 'id': 'simple', |
| 53 | + 'input_': model.Report(case='19-123456', date=now.date()), |
| 54 | + 'other': model.Report(case='19-123456', date=now.date()), |
| 55 | + 'expected': model.Report(case='19-123456', date=now.date()), |
| 56 | + 'strict': False, |
| 57 | + 'id': 'identical-nonstrict', |
56 | 58 | },
|
57 | 59 | {
|
58 |
| - 'input_': model.Report(case='19-123456', date=datetime.datetime.now().date(), link='link'), |
| 60 | + 'input_': model.Report(case='19-123456', date=now.date()), |
| 61 | + 'other': model.Report(case='19-123456', date=now.date()), |
| 62 | + 'expected': model.Report(case='19-123456', date=now.date()), |
| 63 | + 'strict': True, |
| 64 | + 'id': 'identical-strict', |
| 65 | + }, |
| 66 | + { |
| 67 | + 'input_': model.Report(case='19-123456', date=now.date(), link='link'), |
59 | 68 | 'other': None,
|
60 |
| - 'expected': model.Report(case='19-123456', date=datetime.datetime.now().date(), link='link'), |
| 69 | + 'expected': model.Report(case='19-123456', date=now.date(), link='link'), |
| 70 | + 'strict': False, |
61 | 71 | 'id': 'None',
|
62 | 72 | },
|
63 | 73 | {
|
64 |
| - 'input_': model.Report(case='19-123456', date=datetime.datetime.now().date(), link='link'), |
65 |
| - 'other': model.Report(case='19-123456', date=datetime.datetime.now().date(), link='other link', crash=1), |
66 |
| - 'expected': model.Report(case='19-123456', date=datetime.datetime.now().date(), link='link', crash=1), |
| 74 | + 'input_': model.Report(case='19-123456', date=now.date(), link='link'), |
| 75 | + 'other': model.Report(case='19-123456', date=now.date(), link='other link', crash=1), |
| 76 | + 'expected': model.Report(case='19-123456', date=now.date(), link='link', crash=1), |
| 77 | + 'strict': False, |
67 | 78 | 'id': 'complex',
|
68 | 79 | },
|
69 | 80 | ]
|
@@ -145,21 +156,28 @@ def test_compute_fatalities_age(self, input_, expected):
|
145 | 156 | assert [f.age for f in input_.fatalities] == expected
|
146 | 157 |
|
147 | 158 | @pytest.mark.parametrize(
|
148 |
| - 'input_,other,expected', |
149 |
| - [pytest.param(s['input_'], s['other'], s['expected'], id=s['id']) for s in update_model_scenarios], |
| 159 | + 'input_,other,strict,expected', |
| 160 | + [pytest.param(s['input_'], s['other'], s['strict'], s['expected'], id=s['id']) for s in update_model_scenarios], |
150 | 161 | )
|
151 |
| - def test_update_00(self, input_, other, expected): |
| 162 | + def test_update_00(self, input_, other, strict, expected): |
152 | 163 | """Ensure models can be updated."""
|
153 | 164 | actual = input_.copy(deep=True)
|
154 |
| - actual.update(other) |
| 165 | + actual.update(other, strict) |
155 | 166 | assert actual == expected
|
156 | 167 |
|
157 | 168 | def test_update_01(self):
|
158 |
| - """Ensure the case field gets updated.""" |
159 |
| - actual = model.Report(case='19-123456', date=datetime.datetime.now().date()) |
160 |
| - other = model.Report(case='19-123456', date=datetime.datetime.now().date()) |
161 |
| - actual.update(other) |
162 |
| - assert actual == other |
| 169 | + """Ensure required fields are identical in strict mode.""" |
| 170 | + actual = model.Report(case='19-123456', date=now.date()) |
| 171 | + other = model.Report(case='19-654321', date=now.date()) |
| 172 | + with pytest.raises(ValueError): |
| 173 | + actual.update(other, True) |
| 174 | + |
| 175 | + def test_update_02(self): |
| 176 | + """Ensure both instances are of type Report.""" |
| 177 | + actual = model.Report(case='19-123456', date=now.date()) |
| 178 | + other = dict(case='19-654321', date=now.date()) |
| 179 | + with pytest.raises(TypeError): |
| 180 | + actual.update(other) |
163 | 181 |
|
164 | 182 | def test_invalid_case_number(self):
|
165 | 183 | """Ensure the case number has a valid format."""
|
|
0 commit comments