Skip to content

Commit

Permalink
replace nose by pytest (#404)
Browse files Browse the repository at this point in the history
* replace nose by pytest

* fix assert call

* fix assert call

* try make black happy

* Is not alphabetical sorting better?

* try make black happy

* try make black happy

* update project meta

* test_engine.py: fix imports

* fix lint

* test_text.py: fix imports

* test_repr.py: fix imports

* test_extensions.py: fix imports

* test_engine.py: fix imports

* fix ling

* add __init__.py along test_engine.py

* test_moban_factory.py: fix imports

* fix lint

* fix imports

* fix path

* fix path

* raises, does not raise and expand_template_directories changed behavior

* fix path

* fix lint

* call load_engine_factory_and_engines

* call load_engine_factory_and_engines

* attempt to resolve compatibility issue

* fix lint

* moban-ansible missing, maybe?

* os.path.join -> fs.path.join

* add missing imports

Co-authored-by: user <user@germ25.suse.cz>
  • Loading branch information
pgajdos and user committed Sep 23, 2020
1 parent c852a35 commit 111123a
Show file tree
Hide file tree
Showing 40 changed files with 402 additions and 392 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,9 @@ cscope.in.out
cscope.po.out


# remove moban hash dictionary
.moban.hashes

docs/deprecated-level-9-moban-dependency-as-pypi-package/mytravis.yml
docs/deprecated-level-10-moban-dependency-as-git-repo/mytravis.yml
docs/level-1-jinja2-cli/testout
Expand Down
2 changes: 1 addition & 1 deletion .isort.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
line_length=79
# Ignore generated files
skip=setup.py, moban/__init__.py
known_third_party=fs, lml, crayons, jinja2, ruamel.yaml, mock, nose
known_third_party=fs, lml, crayons, jinja2, ruamel.yaml, mock, pytest
indent=' '
multi_line_output=3
length_sort=1
Expand Down
16 changes: 8 additions & 8 deletions CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

In alphabetical order:

* `Andrew Scheller <https://api.github.com/users/lurch>`_
* `Ayan Banerjee <https://api.github.com/users/ayan-b>`_
* `Charlie Liu <https://api.github.com/users/CLiu13>`_
* `John Vandenberg <https://api.github.com/users/jayvdb>`_
* `Joshua Chung <https://api.github.com/users/seeeturtle>`_
* `PRAJWAL M <https://api.github.com/users/PrajwalM2212>`_
* `salotz <https://api.github.com/users/salotz>`_
* `SerekKiri <https://api.github.com/users/SerekKiri>`_
* `Andrew Scheller <https://github.com/lurch>`_
* `Ayan Banerjee <https://github.com/ayan-b>`_
* `Charlie Liu <https://github.com/CLiu13>`_
* `John Vandenberg <https://github.com/jayvdb>`_
* `Joshua Chung <https://github.com/seeeturtle>`_
* `PRAJWAL M <https://github.com/PrajwalM2212>`_
* `salotz <https://github.com/salotz>`_
* `SerekKiri <https://github.com/SerekKiri>`_
8 changes: 5 additions & 3 deletions moban/core/moban_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ def register_extensions(self, extensions):
)
)
if template_type in self.extensions:
self.extensions[template_type] = self.extensions[
user_template_type
].union(extensions[user_template_type])
self.extensions[template_type] = list(
set(self.extensions[user_template_type]).union(
extensions[user_template_type]
)
)
else:
self.extensions[template_type] = extensions[user_template_type]

Expand Down
2 changes: 1 addition & 1 deletion moban/core/mobanfile/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def _list_dir_files(fs, source, dest):
for file_name in fs.listdir(source):
# please note jinja2 does NOT like windows path
# hence the following statement looks like cross platform
# src_file_under_dir = os.path.join(source, file_name)
# src_file_under_dir = fs.path.join(source, file_name)
# but actually it breaks windows instead.
src_file_under_dir = f"{source}/{file_name}"
if fs.isfile(src_file_under_dir):
Expand Down
2 changes: 1 addition & 1 deletion test.bat
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pip freeze

nosetests --with-coverage --cover-package=moban --cover-package=tests || goto :error
pytest --cov=moban || goto :error

flake8 --max-line-length=88 --exclude=docs,.moban.d --ignore=W503,W504 || goto :error

Expand Down
2 changes: 1 addition & 1 deletion test.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pip freeze

nosetests --verbosity=3 --with-cov --with-doctest --doctest-extension=.rst --cover-package moban --cover-package tests
pytest --verbosity=3 --cov=moban --doctest-glob=*.rst
2 changes: 1 addition & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from moban.main import load_engine_factory_and_engines


def setup():
def setUpModule():
load_engine_factory_and_engines()
Empty file added tests/core/__init__.py
Empty file.
10 changes: 5 additions & 5 deletions tests/core/test_context.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import os

import pytest
import fs.path
from nose.tools import eq_

from moban.core.context import Context


def test_context():
context = Context(fs.path.join("tests", "fixtures"))
data = context.get_data("simple.yaml")
eq_(data["simple"], "yaml")
assert data["simple"] == "yaml"


def test_environ_variables():
Expand All @@ -18,7 +18,7 @@ def test_environ_variables():
os.environ[test_var] = test_value
context = Context(fs.path.join("tests", "fixtures"))
data = context.get_data("simple.yaml")
eq_(data[test_var], test_value)
assert data[test_var] == test_value


def test_json_data_overrides_environ_variables():
Expand All @@ -27,7 +27,7 @@ def test_json_data_overrides_environ_variables():
os.environ[test_var] = test_value
context = Context(fs.path.join("tests", "fixtures"))
data = context.get_data("simple.json")
eq_(data[test_var], test_value)
assert data[test_var] == test_value


def test_unknown_data_file():
Expand All @@ -36,4 +36,4 @@ def test_unknown_data_file():
os.environ[test_var] = test_value
context = Context(fs.path.join("tests", "fixtures"))
data = context.get_data("unknown.data")
eq_(data[test_var], test_value)
assert data[test_var] == test_value
14 changes: 7 additions & 7 deletions tests/core/test_engine.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import os

import pytest
import fs.path
from mock import patch
from nose.tools import eq_

from moban.core import ENGINES
from moban.definitions import TemplateTarget
from moban.jinja2.engine import Engine
from moban.data_loaders.yaml import open_yaml
from moban.core.definitions import TemplateTarget
from moban.plugins.yaml_loader import open_yaml
from moban.plugins.jinja2.engine import Engine

MODULE = "moban.core.moban_factory"

Expand Down Expand Up @@ -93,7 +93,7 @@ def test_get_user_defined_engine():
template_types = open_yaml(test_fixture)
ENGINES.register_options(template_types["template_types"])
engine = ENGINES.get_engine("custom_jinja", ".", ".")
eq_(engine.engine.__class__, Engine)
assert engine.engine.__class__ == Engine


def test_custom_file_extension_is_assocated_with_user_defined_engine():
Expand All @@ -103,7 +103,7 @@ def test_custom_file_extension_is_assocated_with_user_defined_engine():
template_types = open_yaml(test_fixture)
ENGINES.register_options(template_types["template_types"])
template_type = ENGINES.get_primary_key("demo_file_suffix")
eq_("custom_jinja", template_type)
assert "custom_jinja" == template_type


def test_built_in_jinja2_file_extension_still_works():
Expand All @@ -113,4 +113,4 @@ def test_built_in_jinja2_file_extension_still_works():
template_types = open_yaml(test_fixture)
ENGINES.register_options(template_types["template_types"])
template_type = ENGINES.get_primary_key("jj2")
eq_("jinja2", template_type)
assert "jinja2" == template_type
57 changes: 32 additions & 25 deletions tests/core/test_moban_factory.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import os
import sys

import pytest
import fs.path
from mock import patch
from lml.plugin import PluginInfo
from nose.tools import eq_, raises

import moban.exceptions as exceptions
from moban.core import ENGINES
from moban.core.context import Context
from moban.jinja2.engine import (
from moban.core.moban_factory import MobanEngine, expand_template_directories
from moban.plugins.jinja2.engine import (
Engine,
is_extension_list_valid,
import_module_of_extension,
)
from moban.core.moban_factory import MobanEngine, expand_template_directories

USER_HOME = fs.path.join("user", "home", ".moban", "repos")

Expand All @@ -23,22 +23,29 @@
class TestPypkg:
def __init__(self):
__package_path__ = os.path.normcase(os.path.dirname(__file__))
self.resources_path = os.path.join(__package_path__, "fixtures")
self.resources_path = fs.path.join(__package_path__, "fixtures")


def test_expand_pypi_dir():
dirs = list(expand_template_directories("testmobans:template-tests"))
dirs = list(
expand_template_directories(
[
"tests/fixtures/template",
"tests/regression_tests/level-7-plugin-dir-cli/my-templates",
]
)
)
for directory in dirs:
assert os.path.exists(directory)
assert os.path.exists(directory[7:])


@patch("moban.deprecated.repo.get_moban_home", return_value=USER_HOME)
@patch("moban.file_system.exists", return_value=True)
@patch("moban.externals.file_system.exists", return_value=True)
def test_expand_repo_dir(_, __):
dirs = list(expand_template_directories("git_repo:template"))

expected = [fs.path.join(USER_HOME, "git_repo", "template")]
eq_(expected, dirs)
assert expected == dirs


def test_default_template_type():
Expand All @@ -57,22 +64,20 @@ def test_default_mako_type(_): # fake mako
assert engine.engine.__class__ == FakeEngine


@raises(exceptions.NoThirdPartyEngine)
def test_unknown_template_type():
ENGINES.get_engine("unknown_template_type", [], "")
with pytest.raises(exceptions.NoThirdPartyEngine):
ENGINES.get_engine("unknown_template_type", [], "")


@raises(exceptions.DirectoryNotFound)
def test_non_existent_tmpl_directries():
ENGINES.get_engine("jj2", "idontexist", "")
with pytest.raises(fs.errors.CreateFailed):
ENGINES.get_engine("jj2", "idontexist", "")


@raises(exceptions.DirectoryNotFound)
def test_non_existent_config_directries():
MobanEngine("tests", "abc", Engine)


@raises(exceptions.DirectoryNotFound)
def test_non_existent_ctx_directries():
Context(["abc"])

Expand All @@ -84,9 +89,9 @@ def test_file_tests():
engine.render_to_file("file_tests.template", "file_tests.yml", output)
with open(output, "r") as output_file:
content = output_file.read()
eq_(content, "yes\nhere")
eq_(engine.file_count, 1)
eq_(engine.templated_count, 1)
assert content == "yes\nhere"
assert engine.file_count == 1
assert engine.templated_count == 1
os.unlink(output)


Expand All @@ -97,9 +102,9 @@ def test_render_string_to_file():
engine.render_string_to_file("{{test}}", "file_tests.yml", output)
with open(output, "r") as output_file:
content = output_file.read()
eq_(content, "here")
eq_(engine.file_count, 1)
eq_(engine.templated_count, 1)
assert content == "here"
assert engine.file_count == 1
assert engine.templated_count == 1
os.unlink(output)


Expand All @@ -110,7 +115,9 @@ def test_global_template_variables():
engine.render_to_file("variables.template", "variables.yml", output)
with open(output, "r") as output_file:
content = output_file.read()
eq_(content, "template: variables.template\ntarget: test.txt\nhere")
assert (
content == "template: variables.template\ntarget: test.txt\nhere"
)
os.unlink(output)


Expand All @@ -121,7 +128,7 @@ def test_nested_global_template_variables():
engine.render_to_file("nested.template", "variables.yml", output)
with open(output, "r") as output_file:
content = output_file.read()
eq_(content, "template: nested.template\ntarget: test.txt\nhere")
assert content == "template: nested.template\ntarget: test.txt\nhere"
os.unlink(output)


Expand All @@ -135,7 +142,7 @@ def test_environ_variables_as_data():
engine.render_to_file("test.template", "this_does_not_exist.yml", output)
with open(output, "r") as output_file:
content = output_file.read()
eq_(content, "foo")
assert content == "foo"
os.unlink(output)


Expand All @@ -146,7 +153,7 @@ def test_string_template():
engine.render_string_to_file("{{simple}}", "simple.yaml", output)
with open(output, "r") as output_file:
content = output_file.read()
eq_(content, "yaml")
assert content == "yaml"
os.unlink(output)


Expand All @@ -157,7 +164,7 @@ def test_extensions_validator():
for fixture in test_fixtures:
actual.append(is_extension_list_valid(fixture))

eq_(expected, actual)
assert expected == actual


def test_import():
Expand Down
4 changes: 2 additions & 2 deletions tests/data_loaders/test_json_loader.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import pytest
import fs.path
from nose.tools import eq_

from moban.plugins.json_loader import open_json


def test_open_json():
content = open_json(fs.path.join("tests", "fixtures", "child.json"))
expected = {"key": "hello world", "pass": "ox"}
eq_(expected, content)
assert expected == content
4 changes: 2 additions & 2 deletions tests/data_loaders/test_merge_dict.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from nose.tools import eq_
import pytest
from ruamel.yaml import YAML

from moban.core.data_loader import merge
Expand Down Expand Up @@ -63,4 +63,4 @@ def test_merge_value_as_list_in_yaml():
"""
)
merged = merge(user, default)
eq_(merged, {"L1": ["a", "b", "c", "d"]})
assert merged == {"L1": ["a", "b", "c", "d"]}

0 comments on commit 111123a

Please sign in to comment.