Skip to content

Commit

Permalink
[internal] 100% test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Hoelzl committed Jul 1, 2018
1 parent 0d7c237 commit c2ae2ad
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
6 changes: 6 additions & 0 deletions tests/unit/test_annotations.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import pytest

from fancy_dict.merger import add, overwrite
from fancy_dict.conditions import if_existing, always
from fancy_dict.annotations import Annotations
Expand Down Expand Up @@ -44,3 +46,7 @@ def test_update_condition(self):
assert add == annotations.merge_method
assert not annotations.finalized
assert always == annotations.condition

def test_attribute_error_if_not_in_defaults(self):
with pytest.raises(AttributeError):
assert not Annotations().no_attribute
16 changes: 14 additions & 2 deletions tests/unit/test_loader.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import os
import json
from unittest import mock
from pathlib import Path
from contextlib import contextmanager
from io import StringIO
from io import StringIO, IOBase

import pytest
import json

from fancy_dict.loader import CompositeLoader, FileLoader, DictLoader, \
KeyAnnotationsConverter, HttpLoader, IoLoader
Expand Down Expand Up @@ -132,6 +133,10 @@ def test_can_load(self, tmpdir):
def test_can_load_false_if_url(self):
assert not FileLoader.can_load("http://www.test.de")

def test_can_load_false_if_os_error(self):
with mock.patch("pathlib.Path.exists", side_effect=OSError):
assert not FileLoader.can_load("os_error")


class TestDictLoader:
def test_load(self):
Expand Down Expand Up @@ -206,6 +211,13 @@ def test_pass_args_to_sub_loader(self, tmpdir):
result = {"key": "value"}
assert result == loader.load("file.yml")

def test_can_load(self, tmpdir):
with file_structure({"file.yml": {"a": 1}}, tmpdir):
assert CompositeLoader(FancyDict).can_load("file.yml")
assert CompositeLoader(FancyDict).can_load("http://www.file.com")
assert CompositeLoader(FancyDict).can_load({})
assert CompositeLoader(FancyDict).can_load(IOBase())


class TestKeyAnnotationsConverter:
def test_key_name_and_defaults(self):
Expand Down

0 comments on commit c2ae2ad

Please sign in to comment.