Skip to content

Commit 111123a

Browse files
pgajdosuser
and
user
authored
replace nose by pytest (#404)
* 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 <[email protected]>
1 parent c852a35 commit 111123a

40 files changed

+402
-392
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,9 @@ cscope.in.out
542542
cscope.po.out
543543

544544

545+
# remove moban hash dictionary
546+
.moban.hashes
547+
545548
docs/deprecated-level-9-moban-dependency-as-pypi-package/mytravis.yml
546549
docs/deprecated-level-10-moban-dependency-as-git-repo/mytravis.yml
547550
docs/level-1-jinja2-cli/testout

.isort.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
line_length=79
33
# Ignore generated files
44
skip=setup.py, moban/__init__.py
5-
known_third_party=fs, lml, crayons, jinja2, ruamel.yaml, mock, nose
5+
known_third_party=fs, lml, crayons, jinja2, ruamel.yaml, mock, pytest
66
indent=' '
77
multi_line_output=3
88
length_sort=1

CONTRIBUTORS.rst

+8-8
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
In alphabetical order:
66

7-
* `Andrew Scheller <https://api.github.com/users/lurch>`_
8-
* `Ayan Banerjee <https://api.github.com/users/ayan-b>`_
9-
* `Charlie Liu <https://api.github.com/users/CLiu13>`_
10-
* `John Vandenberg <https://api.github.com/users/jayvdb>`_
11-
* `Joshua Chung <https://api.github.com/users/seeeturtle>`_
12-
* `PRAJWAL M <https://api.github.com/users/PrajwalM2212>`_
13-
* `salotz <https://api.github.com/users/salotz>`_
14-
* `SerekKiri <https://api.github.com/users/SerekKiri>`_
7+
* `Andrew Scheller <https://github.com/lurch>`_
8+
* `Ayan Banerjee <https://github.com/ayan-b>`_
9+
* `Charlie Liu <https://github.com/CLiu13>`_
10+
* `John Vandenberg <https://github.com/jayvdb>`_
11+
* `Joshua Chung <https://github.com/seeeturtle>`_
12+
* `PRAJWAL M <https://github.com/PrajwalM2212>`_
13+
* `salotz <https://github.com/salotz>`_
14+
* `SerekKiri <https://github.com/SerekKiri>`_

moban/core/moban_factory.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@ def register_extensions(self, extensions):
3434
)
3535
)
3636
if template_type in self.extensions:
37-
self.extensions[template_type] = self.extensions[
38-
user_template_type
39-
].union(extensions[user_template_type])
37+
self.extensions[template_type] = list(
38+
set(self.extensions[user_template_type]).union(
39+
extensions[user_template_type]
40+
)
41+
)
4042
else:
4143
self.extensions[template_type] = extensions[user_template_type]
4244

moban/core/mobanfile/templates.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def _list_dir_files(fs, source, dest):
4343
for file_name in fs.listdir(source):
4444
# please note jinja2 does NOT like windows path
4545
# hence the following statement looks like cross platform
46-
# src_file_under_dir = os.path.join(source, file_name)
46+
# src_file_under_dir = fs.path.join(source, file_name)
4747
# but actually it breaks windows instead.
4848
src_file_under_dir = f"{source}/{file_name}"
4949
if fs.isfile(src_file_under_dir):

test.bat

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
pip freeze
22

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

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

test.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
pip freeze
22

3-
nosetests --verbosity=3 --with-cov --with-doctest --doctest-extension=.rst --cover-package moban --cover-package tests
3+
pytest --verbosity=3 --cov=moban --doctest-glob=*.rst

tests/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from moban.main import load_engine_factory_and_engines
22

33

4-
def setup():
4+
def setUpModule():
55
load_engine_factory_and_engines()

tests/core/__init__.py

Whitespace-only changes.

tests/core/test_context.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import os
22

3+
import pytest
34
import fs.path
4-
from nose.tools import eq_
55

66
from moban.core.context import Context
77

88

99
def test_context():
1010
context = Context(fs.path.join("tests", "fixtures"))
1111
data = context.get_data("simple.yaml")
12-
eq_(data["simple"], "yaml")
12+
assert data["simple"] == "yaml"
1313

1414

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

2323

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

3232

3333
def test_unknown_data_file():
@@ -36,4 +36,4 @@ def test_unknown_data_file():
3636
os.environ[test_var] = test_value
3737
context = Context(fs.path.join("tests", "fixtures"))
3838
data = context.get_data("unknown.data")
39-
eq_(data[test_var], test_value)
39+
assert data[test_var] == test_value

tests/core/test_engine.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import os
22

3+
import pytest
34
import fs.path
45
from mock import patch
5-
from nose.tools import eq_
66

77
from moban.core import ENGINES
8-
from moban.definitions import TemplateTarget
9-
from moban.jinja2.engine import Engine
10-
from moban.data_loaders.yaml import open_yaml
8+
from moban.core.definitions import TemplateTarget
9+
from moban.plugins.yaml_loader import open_yaml
10+
from moban.plugins.jinja2.engine import Engine
1111

1212
MODULE = "moban.core.moban_factory"
1313

@@ -93,7 +93,7 @@ def test_get_user_defined_engine():
9393
template_types = open_yaml(test_fixture)
9494
ENGINES.register_options(template_types["template_types"])
9595
engine = ENGINES.get_engine("custom_jinja", ".", ".")
96-
eq_(engine.engine.__class__, Engine)
96+
assert engine.engine.__class__ == Engine
9797

9898

9999
def test_custom_file_extension_is_assocated_with_user_defined_engine():
@@ -103,7 +103,7 @@ def test_custom_file_extension_is_assocated_with_user_defined_engine():
103103
template_types = open_yaml(test_fixture)
104104
ENGINES.register_options(template_types["template_types"])
105105
template_type = ENGINES.get_primary_key("demo_file_suffix")
106-
eq_("custom_jinja", template_type)
106+
assert "custom_jinja" == template_type
107107

108108

109109
def test_built_in_jinja2_file_extension_still_works():
@@ -113,4 +113,4 @@ def test_built_in_jinja2_file_extension_still_works():
113113
template_types = open_yaml(test_fixture)
114114
ENGINES.register_options(template_types["template_types"])
115115
template_type = ENGINES.get_primary_key("jj2")
116-
eq_("jinja2", template_type)
116+
assert "jinja2" == template_type

tests/core/test_moban_factory.py

+32-25
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
import os
22
import sys
33

4+
import pytest
45
import fs.path
56
from mock import patch
67
from lml.plugin import PluginInfo
7-
from nose.tools import eq_, raises
88

99
import moban.exceptions as exceptions
1010
from moban.core import ENGINES
1111
from moban.core.context import Context
12-
from moban.jinja2.engine import (
12+
from moban.core.moban_factory import MobanEngine, expand_template_directories
13+
from moban.plugins.jinja2.engine import (
1314
Engine,
1415
is_extension_list_valid,
1516
import_module_of_extension,
1617
)
17-
from moban.core.moban_factory import MobanEngine, expand_template_directories
1818

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

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

2828

2929
def test_expand_pypi_dir():
30-
dirs = list(expand_template_directories("testmobans:template-tests"))
30+
dirs = list(
31+
expand_template_directories(
32+
[
33+
"tests/fixtures/template",
34+
"tests/regression_tests/level-7-plugin-dir-cli/my-templates",
35+
]
36+
)
37+
)
3138
for directory in dirs:
32-
assert os.path.exists(directory)
39+
assert os.path.exists(directory[7:])
3340

3441

3542
@patch("moban.deprecated.repo.get_moban_home", return_value=USER_HOME)
36-
@patch("moban.file_system.exists", return_value=True)
43+
@patch("moban.externals.file_system.exists", return_value=True)
3744
def test_expand_repo_dir(_, __):
3845
dirs = list(expand_template_directories("git_repo:template"))
3946

4047
expected = [fs.path.join(USER_HOME, "git_repo", "template")]
41-
eq_(expected, dirs)
48+
assert expected == dirs
4249

4350

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

5966

60-
@raises(exceptions.NoThirdPartyEngine)
6167
def test_unknown_template_type():
62-
ENGINES.get_engine("unknown_template_type", [], "")
68+
with pytest.raises(exceptions.NoThirdPartyEngine):
69+
ENGINES.get_engine("unknown_template_type", [], "")
6370

6471

65-
@raises(exceptions.DirectoryNotFound)
6672
def test_non_existent_tmpl_directries():
67-
ENGINES.get_engine("jj2", "idontexist", "")
73+
with pytest.raises(fs.errors.CreateFailed):
74+
ENGINES.get_engine("jj2", "idontexist", "")
6875

6976

70-
@raises(exceptions.DirectoryNotFound)
7177
def test_non_existent_config_directries():
7278
MobanEngine("tests", "abc", Engine)
7379

7480

75-
@raises(exceptions.DirectoryNotFound)
7681
def test_non_existent_ctx_directries():
7782
Context(["abc"])
7883

@@ -84,9 +89,9 @@ def test_file_tests():
8489
engine.render_to_file("file_tests.template", "file_tests.yml", output)
8590
with open(output, "r") as output_file:
8691
content = output_file.read()
87-
eq_(content, "yes\nhere")
88-
eq_(engine.file_count, 1)
89-
eq_(engine.templated_count, 1)
92+
assert content == "yes\nhere"
93+
assert engine.file_count == 1
94+
assert engine.templated_count == 1
9095
os.unlink(output)
9196

9297

@@ -97,9 +102,9 @@ def test_render_string_to_file():
97102
engine.render_string_to_file("{{test}}", "file_tests.yml", output)
98103
with open(output, "r") as output_file:
99104
content = output_file.read()
100-
eq_(content, "here")
101-
eq_(engine.file_count, 1)
102-
eq_(engine.templated_count, 1)
105+
assert content == "here"
106+
assert engine.file_count == 1
107+
assert engine.templated_count == 1
103108
os.unlink(output)
104109

105110

@@ -110,7 +115,9 @@ def test_global_template_variables():
110115
engine.render_to_file("variables.template", "variables.yml", output)
111116
with open(output, "r") as output_file:
112117
content = output_file.read()
113-
eq_(content, "template: variables.template\ntarget: test.txt\nhere")
118+
assert (
119+
content == "template: variables.template\ntarget: test.txt\nhere"
120+
)
114121
os.unlink(output)
115122

116123

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

127134

@@ -135,7 +142,7 @@ def test_environ_variables_as_data():
135142
engine.render_to_file("test.template", "this_does_not_exist.yml", output)
136143
with open(output, "r") as output_file:
137144
content = output_file.read()
138-
eq_(content, "foo")
145+
assert content == "foo"
139146
os.unlink(output)
140147

141148

@@ -146,7 +153,7 @@ def test_string_template():
146153
engine.render_string_to_file("{{simple}}", "simple.yaml", output)
147154
with open(output, "r") as output_file:
148155
content = output_file.read()
149-
eq_(content, "yaml")
156+
assert content == "yaml"
150157
os.unlink(output)
151158

152159

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

160-
eq_(expected, actual)
167+
assert expected == actual
161168

162169

163170
def test_import():
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
import pytest
12
import fs.path
2-
from nose.tools import eq_
33

44
from moban.plugins.json_loader import open_json
55

66

77
def test_open_json():
88
content = open_json(fs.path.join("tests", "fixtures", "child.json"))
99
expected = {"key": "hello world", "pass": "ox"}
10-
eq_(expected, content)
10+
assert expected == content

tests/data_loaders/test_merge_dict.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from nose.tools import eq_
1+
import pytest
22
from ruamel.yaml import YAML
33

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

0 commit comments

Comments
 (0)