Skip to content
This repository has been archived by the owner on Mar 8, 2021. It is now read-only.

Commit

Permalink
Increase test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
charlax committed Jan 20, 2014
1 parent 27a0a9a commit f60ae65
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[run]
omit = charlatan/_compat.py
2 changes: 1 addition & 1 deletion charlatan/file_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,6 @@ def load_file(filename):
configure_yaml()
content = yaml.load(content)
else:
raise KeyError("Unsupported filetype: '%s'" % filename)
raise ValueError("Unsupported filetype: '%s'" % filename)

return content
1 change: 0 additions & 1 deletion charlatan/tests/data/dependencies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ fixture1:
fields:
foo: bar


fixture2:
fields:
foo: !rel fixture1
Expand Down
Empty file added charlatan/tests/data/test.json
Empty file.
9 changes: 9 additions & 0 deletions charlatan/tests/test_file_format.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import pytest

from charlatan import file_format


def test_non_yaml_file():
"""Verify that we can't open a non-YAML file."""
with pytest.raises(ValueError):
file_format.load_file("./charlatan/tests/data/test.json")
31 changes: 31 additions & 0 deletions charlatan/tests/test_fixture_collection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import pytest

from charlatan import FixturesManager


@pytest.fixture(scope="module")
def collection():
"""Return FixtureCollection."""

manager = FixturesManager()
manager.load("docs/examples/collection.yaml")
return manager.fixture_collection.get("toasters")[0]


def test_repr(collection):
"""Verify the repr."""
assert repr(collection) == "<DictFixtureCollection 'toasters'>"


def test_cant_get_invalid_format(collection):
"""Verify that we can't get an invalid format."""

with pytest.raises(ValueError):
collection.get_all_instances(format="invalid")


def test_cant_get_missing_fixture(collection):
"""Verify that we can't get a missing fixture."""

with pytest.raises(KeyError):
collection.get("missing")
14 changes: 14 additions & 0 deletions charlatan/tests/test_fixtures_manager.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import absolute_import

import pytest

from charlatan import testing
from charlatan import depgraph
from charlatan import FixturesManager
Expand Down Expand Up @@ -108,3 +110,15 @@ def test_constructs_ancestors(self):
fm.get_fixture('fixture3')
self.assertIn('fixture1', fm.cache)
self.assertIn('fixture4', fm.cache)

def test_invalid_hook(self):
"""Verify that can't set an invalid hook."""

manager = FixturesManager()
with pytest.raises(KeyError):
manager.set_hook("invalid", lambda p: p)

def test_set_hook(self):
"""Verify that we can set a hook."""
manager = FixturesManager()
manager.set_hook("before_save", lambda p: p)

0 comments on commit f60ae65

Please sign in to comment.