Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,13 @@ def validate(self) -> validation.Config:
return validation.validate_config(formatted_config, 'general', 'configpath')

def assertValidationError(self, expected):
with self.assertRaises(SystemExit):
with pytest.raises(SystemExit):
self.validate()

# Only one message should be logged.
self.assertEqual(len(self.caplog.records), 1)
assert len(self.caplog.records) == 1

self.assertIn(expected, self.caplog.records[0].message)
assert expected in self.caplog.records[0].message

# We may want to use this assertion more than once per test.
self.caplog.clear()
16 changes: 8 additions & 8 deletions tests/config/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def setUp(self):
def assert0600(self):
permissions = oct(os.stat(self.data._datafile).st_mode & 0o777)
# python2 -> 0600, python3 -> 0o600
self.assertIn(permissions, ['0600', '0o600'])
assert permissions in ['0600', '0o600']

def test_get_set(self):
# "touch" data file.
Expand All @@ -23,18 +23,18 @@ def test_get_set(self):

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

self.assertEqual(self.data.get('key'), 'value')
self.assertEqual(self.data.get_data(), {'old': 'stuff', 'key': 'value'})
assert self.data.get('key') == 'value'
assert self.data.get_data() == {'old': 'stuff', 'key': 'value'}
self.assert0600()

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

self.assertEqual(self.data.get('key'), 'value')
assert self.data.get('key') == 'value'
self.assert0600()

def test_path_attribute(self):
self.assertEqual(self.data.path, self.lists_path)
assert self.data.path == self.lists_path


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

def assertDataPath(self, expected_datapath):
self.assertEqual(expected_datapath, data.get_data_path(self.main_config.taskrc))
assert expected_datapath == data.get_data_path(self.main_config.taskrc)

def test_TASKDATA(self):
"""
Expand All @@ -56,7 +56,7 @@ def test_taskrc_datalocation(self):
"""
When TASKDATA is not set, data.location in taskrc should be respected.
"""
self.assertTrue('TASKDATA' not in os.environ)
assert 'TASKDATA' not in os.environ
self.assertDataPath(self.lists_path)

def test_unassigned(self):
Expand All @@ -67,6 +67,6 @@ def test_unassigned(self):
with open(self.taskrc, 'w'):
pass

self.assertTrue('TASKDATA' not in os.environ)
assert 'TASKDATA' not in os.environ

self.assertDataPath(os.path.expanduser('~/.task'))
84 changes: 41 additions & 43 deletions tests/config/test_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from pathlib import Path
import textwrap
import tomllib
from unittest import TestCase

import pytest

from bugwarrior.config import load

Expand Down Expand Up @@ -60,7 +61,7 @@ def test_path_precedence(self):
try:
config1 = self.create(path1)
self.create(path2)
self.assertEqual(load.get_config_path(), config1)
assert load.get_config_path() == config1
finally:
self.tearDown()

Expand All @@ -69,16 +70,15 @@ def test_legacy(self):
Falls back on .bugwarriorrc if it exists
"""
rc = self.create('.bugwarriorrc')
self.assertEqual(load.get_config_path(), rc)
assert load.get_config_path() == rc

def test_no_file(self):
"""
If no bugwarriorrc exist anywhere, the path to the prefered one is
returned.
"""
self.assertEqual(
load.get_config_path(),
os.path.join(self.tempdir, '.config/bugwarrior/bugwarriorrc'),
assert load.get_config_path() == os.path.join(
self.tempdir, '.config/bugwarrior/bugwarriorrc'
)

def test_BUGWARRIORRC(self):
Expand All @@ -90,7 +90,7 @@ def test_BUGWARRIORRC(self):
os.environ['BUGWARRIORRC'] = rc
self.create('.bugwarriorrc')
self.create('.config/bugwarrior/bugwarriorrc')
self.assertEqual(load.get_config_path(), rc)
assert load.get_config_path() == rc

def test_BUGWARRIORRC_empty(self):
"""
Expand All @@ -99,27 +99,25 @@ def test_BUGWARRIORRC_empty(self):
"""
os.environ['BUGWARRIORRC'] = ''
rc = self.create('.config/bugwarrior/bugwarriorrc')
self.assertEqual(load.get_config_path(), rc)
assert load.get_config_path() == rc


class TestBugwarriorConfigParser(TestCase):
def setUp(self):
self.config = load.BugwarriorConfigParser()
self.config['general'] = {
'someint': '4',
'somenone': '',
'somechar': 'somestring',
}
class TestBugwarriorConfigParser:
@pytest.fixture
def config(self):
config = load.BugwarriorConfigParser()
config['general'] = {'someint': '4', 'somenone': '', 'somechar': 'somestring'}
return config

def test_getint(self):
self.assertEqual(self.config.getint('general', 'someint'), 4)
def test_getint(self, config):
assert config.getint('general', 'someint') == 4

def test_getint_none(self):
self.assertEqual(self.config.getint('general', 'somenone'), None)
def test_getint_none(self, config):
assert config.getint('general', 'somenone') is None

def test_getint_valueerror(self):
with self.assertRaises(ValueError):
self.config.getint('general', 'somechar')
def test_getint_valueerror(self, config):
with pytest.raises(ValueError):
config.getint('general', 'somechar')


class TestParseFile(LoadTest):
Expand All @@ -146,9 +144,7 @@ def test_ini(self):
)
config = load.parse_file(config_path)

self.assertEqual(
config, {'flavor': {'general': {'foo': 'bar'}}, 'services': []}
)
assert config == {'flavor': {'general': {'foo': 'bar'}}, 'services': []}

def test_toml_invalid(self):
config_path = self.create('.bugwarrior.toml')
Expand All @@ -160,7 +156,7 @@ def test_toml_invalid(self):
""")
)

with self.assertRaises(tomllib.TOMLDecodeError):
with pytest.raises(tomllib.TOMLDecodeError):
load.parse_file(config_path)

def test_ini_invalid(self):
Expand All @@ -173,7 +169,7 @@ def test_ini_invalid(self):
""")
)

with self.assertRaises(configparser.MissingSectionHeaderError):
with pytest.raises(configparser.MissingSectionHeaderError):
load.parse_file(config_path)

def test_toml_flavors(self):
Expand All @@ -182,9 +178,10 @@ def test_toml_flavors(self):
with open(config_path, 'w') as fout:
fout.write('[flavor.myflavor]\ntargets = ["my_gitlab"]')
config = load.parse_file(config_path)
self.assertEqual(
config, {'flavor': {'myflavor': {'targets': ['my_gitlab']}}, 'services': []}
)
assert config == {
'flavor': {'myflavor': {'targets': ['my_gitlab']}},
'services': [],
}

def test_ini_flavors(self):
config_path = self.create('.bugwarriorrc')
Expand All @@ -197,9 +194,10 @@ def test_ini_flavors(self):
)
config = load.parse_file(config_path)

self.assertEqual(
config, {'flavor': {'myflavor': {'targets': 'my_gitlab'}}, 'services': []}
)
assert config == {
'flavor': {'myflavor': {'targets': 'my_gitlab'}},
'services': [],
}

def test_ini_options_renamed(self):
"""
Expand All @@ -221,11 +219,11 @@ def test_ini_options_renamed(self):
config = load.parse_file(config_path)

baz_service = next(svc for svc in config['services'] if svc['target'] == 'baz')
self.assertIn('optionname', baz_service)
self.assertNotIn('prefix.optionname', baz_service)
assert 'optionname' in baz_service
assert 'prefix.optionname' not in baz_service

self.assertIn('log_level', config['flavor']['general'])
self.assertNotIn('log.level', config['flavor']['general'])
assert 'log_level' in config['flavor']['general']
assert 'log.level' not in config['flavor']['general']

def test_ini_missing_prefix(self):
config_path = self.create('.bugwarriorrc')
Expand All @@ -240,7 +238,7 @@ def test_ini_missing_prefix(self):
""")
)

with self.assertRaises(SystemExit):
with pytest.raises(SystemExit):
load.parse_file(config_path)

def test_ini_wrong_prefix(self):
Expand All @@ -256,7 +254,7 @@ def test_ini_wrong_prefix(self):
""")
)

with self.assertRaises(SystemExit):
with pytest.raises(SystemExit):
load.parse_file(config_path)


Expand All @@ -276,8 +274,8 @@ def test_main_section_does_not_exist(self):
""")
)

with self.assertRaises(SystemExit):
with pytest.raises(SystemExit):
load.load_config("general", False)

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