Skip to content
Permalink
Browse files

tests: add tests for `_load_config`

  • Loading branch information...
etienne-napoleone committed Dec 20, 2018
1 parent 04291a6 commit 211ea1616e9a2667d32d0f1b03e66cacab2c4a17
Showing with 53 additions and 0 deletions.
  1. +5 −0 tests/mock.py
  2. +48 −0 tests/test_goutte.py
@@ -56,3 +56,8 @@ def get_all_droplets(self):
return [
Droplet(name='testdroplet')
]


class File:
def __init__(self, name=None):
self.name = name
@@ -1,4 +1,6 @@
import digitalocean
import pytest
import toml

from goutte import __version__
from goutte import main
@@ -9,6 +11,52 @@ def test_version():
assert __version__ == '1.0.0'


def test_load_config(monkeypatch):
def load(file):
return {'retention': 2}
monkeypatch.setattr(toml, 'load', load)
assert main._load_config(mock.File(name='test.toml'))['retention'] == 2


def test_load_config_raise_typeerror(caplog, monkeypatch):
def load(file):
raise TypeError
monkeypatch.setattr(toml, 'load', load)
with caplog.at_level('INFO'):
with pytest.raises(SystemExit) as e:
main._load_config(mock.File(name='test.toml'))
assert len(caplog.records) == 1
assert caplog.records[0].levelname == 'CRITICAL'
assert e.type == SystemExit
assert e.value.code == 1


def test_load_config_raise_tomldecodeerror(caplog, monkeypatch):
def load(file):
raise toml.TomlDecodeError
monkeypatch.setattr(toml, 'load', load)
with caplog.at_level('INFO'):
with pytest.raises(SystemExit) as e:
main._load_config(mock.File(name='test.toml'))
assert len(caplog.records) == 1
assert caplog.records[0].levelname == 'CRITICAL'
assert e.type == SystemExit
assert e.value.code == 1


def test_load_config_config_keyerror(caplog, monkeypatch):
def load(file):
return {}
monkeypatch.setattr(toml, 'load', load)
with caplog.at_level('INFO'):
with pytest.raises(SystemExit) as e:
main._load_config(mock.File(name='test.toml'))
assert len(caplog.records) == 1
assert caplog.records[0].levelname == 'CRITICAL'
assert e.type == SystemExit
assert e.value.code == 1


def test_process_droplets(caplog, monkeypatch):
def get_droplets(names):
return [mock.Droplet(name='testdroplet')]

0 comments on commit 211ea16

Please sign in to comment.
You can’t perform that action at this time.