Skip to content

Commit 7db6665

Browse files
Lotramryneeverett
authored andcommitted
Migrate unittest assertions to pytest asserts
1 parent 6c11ae1 commit 7db6665

36 files changed

Lines changed: 486 additions & 527 deletions

tests/base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,13 @@ def validate(self) -> validation.Config:
139139
return validation.validate_config(formatted_config, 'general', 'configpath')
140140

141141
def assertValidationError(self, expected):
142-
with self.assertRaises(SystemExit):
142+
with pytest.raises(SystemExit):
143143
self.validate()
144144

145145
# Only one message should be logged.
146-
self.assertEqual(len(self.caplog.records), 1)
146+
assert len(self.caplog.records) == 1
147147

148-
self.assertIn(expected, self.caplog.records[0].message)
148+
assert expected in self.caplog.records[0].message
149149

150150
# We may want to use this assertion more than once per test.
151151
self.caplog.clear()

tests/config/test_data.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def setUp(self):
1414
def assert0600(self):
1515
permissions = oct(os.stat(self.data._datafile).st_mode & 0o777)
1616
# python2 -> 0600, python3 -> 0o600
17-
self.assertIn(permissions, ['0600', '0o600'])
17+
assert permissions in ['0600', '0o600']
1818

1919
def test_get_set(self):
2020
# "touch" data file.
@@ -23,18 +23,18 @@ def test_get_set(self):
2323

2424
self.data.set('key', 'value')
2525

26-
self.assertEqual(self.data.get('key'), 'value')
27-
self.assertEqual(self.data.get_data(), {'old': 'stuff', 'key': 'value'})
26+
assert self.data.get('key') == 'value'
27+
assert self.data.get_data() == {'old': 'stuff', 'key': 'value'}
2828
self.assert0600()
2929

3030
def test_set_first_time(self):
3131
self.data.set('key', 'value')
3232

33-
self.assertEqual(self.data.get('key'), 'value')
33+
assert self.data.get('key') == 'value'
3434
self.assert0600()
3535

3636
def test_path_attribute(self):
37-
self.assertEqual(self.data.path, self.lists_path)
37+
assert self.data.path == self.lists_path
3838

3939

4040
class TestGetDataPath(ConfigTest):
@@ -43,7 +43,7 @@ def setUp(self):
4343
self.main_config = schema.MainSectionConfig(targets=[])
4444

4545
def assertDataPath(self, expected_datapath):
46-
self.assertEqual(expected_datapath, data.get_data_path(self.main_config.taskrc))
46+
assert expected_datapath == data.get_data_path(self.main_config.taskrc)
4747

4848
def test_TASKDATA(self):
4949
"""
@@ -56,7 +56,7 @@ def test_taskrc_datalocation(self):
5656
"""
5757
When TASKDATA is not set, data.location in taskrc should be respected.
5858
"""
59-
self.assertTrue('TASKDATA' not in os.environ)
59+
assert 'TASKDATA' not in os.environ
6060
self.assertDataPath(self.lists_path)
6161

6262
def test_unassigned(self):
@@ -67,6 +67,6 @@ def test_unassigned(self):
6767
with open(self.taskrc, 'w'):
6868
pass
6969

70-
self.assertTrue('TASKDATA' not in os.environ)
70+
assert 'TASKDATA' not in os.environ
7171

7272
self.assertDataPath(os.path.expanduser('~/.task'))

tests/config/test_load.py

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import tomllib
77
from unittest import TestCase
88

9+
import pytest
10+
911
from bugwarrior.config import load
1012

1113
from ..base import ConfigTest
@@ -60,7 +62,7 @@ def test_path_precedence(self):
6062
try:
6163
config1 = self.create(path1)
6264
self.create(path2)
63-
self.assertEqual(load.get_config_path(), config1)
65+
assert load.get_config_path() == config1
6466
finally:
6567
self.tearDown()
6668

@@ -69,16 +71,15 @@ def test_legacy(self):
6971
Falls back on .bugwarriorrc if it exists
7072
"""
7173
rc = self.create('.bugwarriorrc')
72-
self.assertEqual(load.get_config_path(), rc)
74+
assert load.get_config_path() == rc
7375

7476
def test_no_file(self):
7577
"""
7678
If no bugwarriorrc exist anywhere, the path to the prefered one is
7779
returned.
7880
"""
79-
self.assertEqual(
80-
load.get_config_path(),
81-
os.path.join(self.tempdir, '.config/bugwarrior/bugwarriorrc'),
81+
assert load.get_config_path() == os.path.join(
82+
self.tempdir, '.config/bugwarrior/bugwarriorrc'
8283
)
8384

8485
def test_BUGWARRIORRC(self):
@@ -90,7 +91,7 @@ def test_BUGWARRIORRC(self):
9091
os.environ['BUGWARRIORRC'] = rc
9192
self.create('.bugwarriorrc')
9293
self.create('.config/bugwarrior/bugwarriorrc')
93-
self.assertEqual(load.get_config_path(), rc)
94+
assert load.get_config_path() == rc
9495

9596
def test_BUGWARRIORRC_empty(self):
9697
"""
@@ -99,7 +100,7 @@ def test_BUGWARRIORRC_empty(self):
99100
"""
100101
os.environ['BUGWARRIORRC'] = ''
101102
rc = self.create('.config/bugwarrior/bugwarriorrc')
102-
self.assertEqual(load.get_config_path(), rc)
103+
assert load.get_config_path() == rc
103104

104105

105106
class TestBugwarriorConfigParser(TestCase):
@@ -112,13 +113,13 @@ def setUp(self):
112113
}
113114

114115
def test_getint(self):
115-
self.assertEqual(self.config.getint('general', 'someint'), 4)
116+
assert self.config.getint('general', 'someint') == 4
116117

117118
def test_getint_none(self):
118-
self.assertEqual(self.config.getint('general', 'somenone'), None)
119+
assert self.config.getint('general', 'somenone') is None
119120

120121
def test_getint_valueerror(self):
121-
with self.assertRaises(ValueError):
122+
with pytest.raises(ValueError):
122123
self.config.getint('general', 'somechar')
123124

124125

@@ -146,9 +147,7 @@ def test_ini(self):
146147
)
147148
config = load.parse_file(config_path)
148149

149-
self.assertEqual(
150-
config, {'flavor': {'general': {'foo': 'bar'}}, 'services': []}
151-
)
150+
assert config == {'flavor': {'general': {'foo': 'bar'}}, 'services': []}
152151

153152
def test_toml_invalid(self):
154153
config_path = self.create('.bugwarrior.toml')
@@ -160,7 +159,7 @@ def test_toml_invalid(self):
160159
""")
161160
)
162161

163-
with self.assertRaises(tomllib.TOMLDecodeError):
162+
with pytest.raises(tomllib.TOMLDecodeError):
164163
load.parse_file(config_path)
165164

166165
def test_ini_invalid(self):
@@ -173,7 +172,7 @@ def test_ini_invalid(self):
173172
""")
174173
)
175174

176-
with self.assertRaises(configparser.MissingSectionHeaderError):
175+
with pytest.raises(configparser.MissingSectionHeaderError):
177176
load.parse_file(config_path)
178177

179178
def test_toml_flavors(self):
@@ -182,9 +181,10 @@ def test_toml_flavors(self):
182181
with open(config_path, 'w') as fout:
183182
fout.write('[flavor.myflavor]\ntargets = ["my_gitlab"]')
184183
config = load.parse_file(config_path)
185-
self.assertEqual(
186-
config, {'flavor': {'myflavor': {'targets': ['my_gitlab']}}, 'services': []}
187-
)
184+
assert config == {
185+
'flavor': {'myflavor': {'targets': ['my_gitlab']}},
186+
'services': [],
187+
}
188188

189189
def test_ini_flavors(self):
190190
config_path = self.create('.bugwarriorrc')
@@ -197,9 +197,10 @@ def test_ini_flavors(self):
197197
)
198198
config = load.parse_file(config_path)
199199

200-
self.assertEqual(
201-
config, {'flavor': {'myflavor': {'targets': 'my_gitlab'}}, 'services': []}
202-
)
200+
assert config == {
201+
'flavor': {'myflavor': {'targets': 'my_gitlab'}},
202+
'services': [],
203+
}
203204

204205
def test_ini_options_renamed(self):
205206
"""
@@ -221,11 +222,11 @@ def test_ini_options_renamed(self):
221222
config = load.parse_file(config_path)
222223

223224
baz_service = next(svc for svc in config['services'] if svc['target'] == 'baz')
224-
self.assertIn('optionname', baz_service)
225-
self.assertNotIn('prefix.optionname', baz_service)
225+
assert 'optionname' in baz_service
226+
assert 'prefix.optionname' not in baz_service
226227

227-
self.assertIn('log_level', config['flavor']['general'])
228-
self.assertNotIn('log.level', config['flavor']['general'])
228+
assert 'log_level' in config['flavor']['general']
229+
assert 'log.level' not in config['flavor']['general']
229230

230231
def test_ini_missing_prefix(self):
231232
config_path = self.create('.bugwarriorrc')
@@ -240,7 +241,7 @@ def test_ini_missing_prefix(self):
240241
""")
241242
)
242243

243-
with self.assertRaises(SystemExit):
244+
with pytest.raises(SystemExit):
244245
load.parse_file(config_path)
245246

246247
def test_ini_wrong_prefix(self):
@@ -256,7 +257,7 @@ def test_ini_wrong_prefix(self):
256257
""")
257258
)
258259

259-
with self.assertRaises(SystemExit):
260+
with pytest.raises(SystemExit):
260261
load.parse_file(config_path)
261262

262263

@@ -276,8 +277,8 @@ def test_main_section_does_not_exist(self):
276277
""")
277278
)
278279

279-
with self.assertRaises(SystemExit):
280+
with pytest.raises(SystemExit):
280281
load.load_config("general", False)
281282

282-
self.assertEqual(len(self.caplog.records), 1)
283-
self.assertIn("No section: 'general'", self.caplog.records[0].message)
283+
assert len(self.caplog.records) == 1
284+
assert "No section: 'general'" in self.caplog.records[0].message

0 commit comments

Comments
 (0)