Skip to content

Commit

Permalink
tests: Use pytest, separate dev dependencies
Browse files Browse the repository at this point in the history
* Use pytest instead of nosetests

* Move all dev-related dependencies to `dev-dependencies` and hence
  minimize the footprint.

Signed-off-by: mr.Shu <[email protected]>
  • Loading branch information
mrshu committed Sep 21, 2019
1 parent b5b68ac commit bff570e
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ before_install:
install:
- poetry install
script:
- poetry run nosetests --with-coverage --cover-package=envtoml
- poetry run pytest --cov=envtoml
after_success:
- coveralls
37 changes: 29 additions & 8 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ classifiers = [
[tool.poetry.dependencies]
python = "^3.5"
toml = "^0.10.0"
nose = "^1.3"
coverage = "^4.5"

[tool.poetry.dev-dependencies]
pytest = "^3.0"
coverage = "^4.5"
pytest-cov = "^2.7"

[build-system]
requires = ["poetry>=0.12"]
Expand Down
32 changes: 12 additions & 20 deletions tests/test_envtoml.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from envtoml import __version__
from envtoml import load, loads
from nose.tools import assert_equals
import os


Expand All @@ -22,61 +21,54 @@ def test_version():


def test_load():
assert_equals(load(open('./tests/test_simple.toml')), SIMPLE_OUTPUT)
assert_equals(load(open('./tests/test_complex.toml')), MORE_COMPLEX_OUTPUT)
assert load(open('./tests/test_simple.toml')) == SIMPLE_OUTPUT
assert load(open('./tests/test_complex.toml')) == MORE_COMPLEX_OUTPUT


def test_load_with_replace():
os.environ['MY_CONFIG_VAR'] = "10"
assert_equals(load(open('./tests/test_simple_replacement.toml')),
SIMPLE_OUTPUT)
assert load(open('./tests/test_simple_replacement.toml')) == SIMPLE_OUTPUT


def test_loads():
assert_equals(loads('{x = 5, y = 10}'), SIMPLE_OUTPUT)
assert loads('{x = 5, y = 10}') == SIMPLE_OUTPUT


def test_loads_with_replace():
os.environ['MY_CONFIG_VAR'] = "10"
assert_equals(loads("{x = 5, y = '$MY_CONFIG_VAR'}"), SIMPLE_OUTPUT)
assert loads("{x = 5, y = '$MY_CONFIG_VAR'}") == SIMPLE_OUTPUT


def test_loads_with_replace_str():
os.environ['MY_STR_CONFIG_VAR'] = "Hello"
assert_equals(loads("{name = '$MY_STR_CONFIG_VAR'}"),
{'name': 'Hello'})
assert loads("{name = '$MY_STR_CONFIG_VAR'}") == {'name': 'Hello'}


def test_loads_with_replace_float():
os.environ['MY_FLOAT_CONFIG_VAR'] = "3.14"
assert_equals(loads("{val = '$MY_FLOAT_CONFIG_VAR'}"),
{'val': 3.14})
assert loads("{val = '$MY_FLOAT_CONFIG_VAR'}") == {'val': 3.14}


def test_loads_with_replace_bool():
os.environ['MY_BOOL_CONFIG_VAR'] = 'true'
assert_equals(loads("{is_set = '$MY_BOOL_CONFIG_VAR'}"),
{'is_set': True})
assert loads("{is_set = '$MY_BOOL_CONFIG_VAR'}") == {'is_set': True}

os.environ['MY_BOOL_CONFIG_VAR'] = 'false'
assert_equals(loads("{is_set = '$MY_BOOL_CONFIG_VAR'}"),
{'is_set': False})
assert loads("{is_set = '$MY_BOOL_CONFIG_VAR'}") == {'is_set': False}


def test_complex_replacement():
os.environ['MY_LAPTOP_NAME'] = 'laptop'
os.environ['MY_LAPTOP_PRICE'] = '1000'
os.environ['MY_IS_LAPTOP_SOLD'] = 'true'

assert_equals(load(open('./tests/test_complex_replacement.toml')),
MORE_COMPLEX_OUTPUT)
assert load(open('./tests/test_complex_replacement.toml')) == MORE_COMPLEX_OUTPUT # noqa


def test_loads_with_replace_and_empty_value():
assert_equals(loads("{x = 5, y = '$NON_EXISTENT_VAR'}"), {'x': 5, 'y': ''})
assert loads("{x = 5, y = '$NON_EXISTENT_VAR'}") == {'x': 5, 'y': ''}


def test_loads_with_replace_dict():
os.environ['MY_CONFIG_VAR'] = "{z = 123}"
assert_equals(loads("{x = 5, y = '$MY_CONFIG_VAR'}"),
{'x': 5, 'y': {'z': 123}})
assert loads("{x = 5, y = '$MY_CONFIG_VAR'}") == {'x': 5, 'y': {'z': 123}}

0 comments on commit bff570e

Please sign in to comment.