Skip to content

Commit

Permalink
Do not require [gtimelog] section. (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
icemac authored Dec 11, 2023
1 parent 2380749 commit 08c1c83
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 21 deletions.
8 changes: 2 additions & 6 deletions gtimelog2tick.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,14 @@ def read_config(config_file: pathlib.Path) -> dict:
f"Section [gtimelog2tick] is not present in {config_file} config"
" file.")

if not config.has_section('gtimelog'):
raise ConfigurationError(
f"Section [gtimelog] is not present in {config_file} config file.")

subscription_id = config['gtimelog2tick'].get('subscription_id')
token = config['gtimelog2tick'].get('token')
user_id = config['gtimelog2tick'].get('user_id')
email = config['gtimelog2tick'].get('email')
timelog = config['gtimelog2tick'].get('timelog')
ticklog = config['gtimelog2tick'].get('ticklog')
requested_projects = config['gtimelog2tick'].get('projects')
midnight = config['gtimelog'].get('virtual_midnight', '06:00')
requested_projects = config.get('gtimelog2tick', 'projects', fallback='')
midnight = config.get('gtimelog', 'virtual_midnight', fallback='06:00')

if not subscription_id:
raise ConfigurationError(
Expand Down
15 changes: 0 additions & 15 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -684,20 +684,10 @@ def test_gtimelog2tick__read_config__2(tmpdir):
assert err.match(r'Section \[gtimelog2tick\] is not present')


def test_gtimelog2tick__read_config__3(tmpdir):
"""It renders an exception if the section gtimelog does not exist."""
path = pathlib.Path(tmpdir) / 'config.ini'
path.write_text('[gtimelog2tick]')
with pytest.raises(gtimelog2tick.ConfigurationError) as err:
gtimelog2tick.read_config(path)
assert err.match(r'Section \[gtimelog\] is not present')


def test_gtimelog2tick__read_config__4(tmpdir):
"""It renders an exception if subscription_id is missing."""
path = pathlib.Path(tmpdir) / 'config.ini'
path.write_text(textwrap.dedent("""\
[gtimelog]
[gtimelog2tick]"""))
with pytest.raises(gtimelog2tick.ConfigurationError) as err:
gtimelog2tick.read_config(path)
Expand All @@ -709,7 +699,6 @@ def test_gtimelog2tick__read_config__5(tmpdir):
"""It renders an exception if token is missing."""
path = pathlib.Path(tmpdir) / 'config.ini'
path.write_text(textwrap.dedent("""\
[gtimelog]
[gtimelog2tick]
subscription_id = 123"""))
with pytest.raises(gtimelog2tick.ConfigurationError) as err:
Expand All @@ -722,7 +711,6 @@ def test_gtimelog2tick__read_config__6(tmpdir):
"""It renders an exception if user_id is missing."""
path = pathlib.Path(tmpdir) / 'config.ini'
path.write_text(textwrap.dedent("""\
[gtimelog]
[gtimelog2tick]
subscription_id = 123
token = <TOKEN>"""))
Expand All @@ -736,7 +724,6 @@ def test_gtimelog2tick__read_config__7(tmpdir):
"""It renders an exception if email is missing."""
path = pathlib.Path(tmpdir) / 'config.ini'
path.write_text(textwrap.dedent("""\
[gtimelog]
[gtimelog2tick]
subscription_id = 123
token = <TOKEN>
Expand Down Expand Up @@ -767,7 +754,6 @@ def test_gtimelog2tick__read_config__9(tmpdir):
"""It renders an exception if timelog file does not exist."""
path = pathlib.Path(tmpdir) / 'config.ini'
path.write_text(textwrap.dedent("""\
[gtimelog]
[gtimelog2tick]
subscription_id = 123
token = <TOKEN>
Expand All @@ -783,7 +769,6 @@ def test_gtimelog2tick__read_config__10(tmpdir):
"""It renders an exception if ticklog file ist nor writeable."""
path = pathlib.Path(tmpdir) / 'config.ini'
path.write_text(textwrap.dedent("""\
[gtimelog]
[gtimelog2tick]
subscription_id = 123
token = <TOKEN>
Expand Down

0 comments on commit 08c1c83

Please sign in to comment.