-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #74 from alchemistry/test-all-amber
increase coverage to 100% (test ALL AMBER files and all of __init__)
- Loading branch information
Showing
2 changed files
with
96 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
'''Tests for utility functions''' | ||
|
||
import pytest | ||
import pickle | ||
|
||
import alchemtest | ||
|
||
|
||
def test_version(): | ||
assert alchemtest.__version__ | ||
|
||
|
||
@pytest.fixture | ||
def bunch(): | ||
return alchemtest.Bunch(data=[0, 1, 1, 2, 3, 5], DESCR="Fibonacci") | ||
|
||
class TestBunch: | ||
def test_getattr_key(self, bunch): | ||
assert bunch["DESCR"] == "Fibonacci" | ||
|
||
def test_getattr_key(self, bunch): | ||
assert bunch.DESCR == "Fibonacci" | ||
|
||
def test_setattr_key(self, bunch): | ||
bunch["foo"] = "bar" | ||
assert bunch.foo == "bar" | ||
|
||
def test_setattr_dot(self, bunch): | ||
bunch.foo = "bar" | ||
assert bunch.foo == "bar" | ||
|
||
def test_missing_attr_AttributeError(self, bunch): | ||
with pytest.raises(AttributeError): | ||
bunch.unknown_attribute | ||
|
||
def test_missing_key_KeyError(self, bunch): | ||
with pytest.raises(KeyError): | ||
bunch["unknown key"] | ||
|
||
def test_dir(self, bunch): | ||
bunch.a = "additional" | ||
assert sorted(dir(bunch)) == ["DESCR", "a", "data"] | ||
|
||
def test_serialize(self, bunch): | ||
bunch_copy = pickle.loads(pickle.dumps(bunch)) | ||
assert bunch_copy == bunch |