Skip to content

Commit 0f6b38f

Browse files
authored
Windows build (#406)
* 💚 fix windows build * 💄 update coding style * 💚 update mock to unittest.mock
1 parent 111123a commit 0f6b38f

17 files changed

+29
-33
lines changed

CONTRIBUTORS.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
8 contributors
2+
9 contributors
33
================================================================================
44

55
In alphabetical order:
@@ -9,6 +9,7 @@ In alphabetical order:
99
* `Charlie Liu <https://github.com/CLiu13>`_
1010
* `John Vandenberg <https://github.com/jayvdb>`_
1111
* `Joshua Chung <https://github.com/seeeturtle>`_
12+
* `pgajdos <https://github.com/pgajdos>`_
1213
* `PRAJWAL M <https://github.com/PrajwalM2212>`_
1314
* `salotz <https://github.com/salotz>`_
1415
* `SerekKiri <https://github.com/SerekKiri>`_

moban/core/moban_factory.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import logging
33
from collections import defaultdict
44

5-
from fs.errors import ResourceNotFound
5+
from fs.errors import ResourceNotFound, InvalidCharsInPath
66
from lml.plugin import PluginManager
77

88
from moban import constants, exceptions
@@ -120,7 +120,12 @@ def number_of_templated_files(self):
120120

121121
def render_to_file(self, template_file, data_file, output_file):
122122
data = self.context.get_data(data_file)
123-
template = self.engine.get_template(template_file)
123+
try:
124+
template = self.engine.get_template(template_file)
125+
except InvalidCharsInPath:
126+
return self.render_string_to_file(
127+
template_file, data_file, output_file
128+
)
124129
try:
125130
template_abs_path = self.template_fs.geturl(
126131
template_file, purpose="fs"
@@ -204,7 +209,7 @@ def apply_template(self, template_abs_path, template, data, output_file):
204209
# win32 does not work
205210
pass
206211
return flag
207-
except exceptions.FileNotFound:
212+
except (exceptions.FileNotFound, InvalidCharsInPath):
208213
# the template is a string from command line
209214
LOG.info(f"{template_abs_path} is not a file")
210215
self.buffered_writer.write_file_out(output_file, rendered_content)

test.bat

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
11
pip freeze
22

3-
pytest --cov=moban || goto :error
4-
5-
flake8 --max-line-length=88 --exclude=docs,.moban.d --ignore=W503,W504 || goto :error
6-
7-
:error
8-
echo Failed with error #%errorlevel%.
9-
exit /b %errorlevel%
3+
pytest --verbosity=3 --cov=moban --doctest-glob=*.rst

tests/core/test_engine.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import os
2+
from unittest.mock import patch
23

3-
import pytest
44
import fs.path
5-
from mock import patch
65

76
from moban.core import ENGINES
87
from moban.core.definitions import TemplateTarget

tests/core/test_moban_factory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import os
22
import sys
3+
from unittest.mock import patch
34

45
import pytest
56
import fs.path
6-
from mock import patch
77
from lml.plugin import PluginInfo
88

99
import moban.exceptions as exceptions

tests/deprecated/test_handle_requires.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
from unittest.mock import patch
2+
13
import pytest
2-
from mock import patch
34

45
from moban.deprecated import GitRequire
56

@@ -60,7 +61,7 @@ def test_handle_requires_repos_with_submodule(
6061
fake_git_clone.assert_called_with(
6162
[GitRequire(git_url="https://github.com/my/repo", submodule=True)]
6263
)
63-
assert fake_pip_install.called == False
64+
assert fake_pip_install.called is False
6465

6566

6667
def test_is_repo():

tests/deprecated/test_repo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import unittest
2+
from unittest.mock import patch
23

34
import pytest
45
import fs.path
5-
from mock import patch
66

77
from moban.deprecated import GitRequire
88
from moban.exceptions import NoGitCommand
@@ -46,7 +46,7 @@ def test_checkout_new(self, fake_repo, local_folder_exists, *_):
4646
depth=2,
4747
)
4848
repo = fake_repo.return_value
49-
assert repo.git.submodule.called == False
49+
assert repo.git.submodule.called is False
5050

5151
def test_checkout_new_with_submodules(
5252
self, fake_repo, local_folder_exists, *_

tests/integration_tests/test_command_line_options.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
import sys
33
import unittest
44
from shutil import copyfile
5+
from unittest.mock import MagicMock, patch
56

67
import fs
78
import pytest
8-
from mock import MagicMock, patch
99

1010
from moban.core.definitions import TemplateTarget
1111

tests/jinja2/test_engine.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
def test_jinja2_template():
99
path = fs.path.join("tests", "fixtures", "jinja_tests")
1010
fsys = file_system.get_multi_fs([path])
11-
engine = Engine(fsys)
11+
options = {"extensions": ["test:moban.externals.file_system.exists"]}
12+
engine = Engine(fsys, options)
1213
template = engine.get_template("file_tests.template")
1314
data = dict(test="here")
1415
result = engine.apply_template(template, data, None)

tests/mobanfile/test_mobanfile.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
from unittest.mock import patch
2+
13
import pytest
24
import fs.path
3-
from mock import patch
45

56
from moban.core.definitions import TemplateTarget
67

tests/mobanfile/test_templates.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import unittest
2+
from unittest.mock import patch
23

34
import pytest
45
import fs.path
5-
from mock import patch
66

77
from moban.core.mobanfile.templates import handle_template
88

tests/requirements.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@ pytest
22
pytest-cov
33
codecov
44
coverage
5-
mock
65
yamllint
76
flake8
87
black
98
isort
109
moban-handlebars
11-
moban-ansible
1210
pypi-mobans-pkg==0.0.12
1311
arrow
1412
jinja2_time
@@ -18,4 +16,3 @@ jinja2-python-version>=1.1.2
1816
httpfs
1917
collective.checkdocs
2018
Pygments
21-

tests/test_file_system.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
import sys
33
import stat
44
from shutil import rmtree
5+
from unittest.mock import patch
56

67
import fs
78
import pytest
8-
from mock import patch
99

1010
from moban.externals import file_system
1111
from moban.exceptions import FileNotFound, UnsupportedPyFS2Protocol

tests/test_main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
import sys
33
import unittest
44
from shutil import copyfile
5+
from unittest.mock import MagicMock, patch
56

67
import fs
78
import pytest
8-
from mock import MagicMock, patch
99

1010
import moban.exceptions as exceptions
1111

tests/test_regression.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
import sys
33
import filecmp
44
import unittest
5+
from unittest.mock import patch
56

67
import fs
7-
from mock import patch
88

99
from moban.main import main
1010
from .utils import Docs

tests/test_reporter.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import sys
22
import unittest
3-
4-
import pytest
5-
from mock import patch
3+
from unittest.mock import patch
64

75
from moban.externals import reporter
86

tests/utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
import sys
33
import unittest
44
from textwrap import dedent
5+
from unittest.mock import patch
56

67
import fs
7-
import pytest
8-
from mock import patch
98
from fs.opener.parse import parse_fs_url
109

1110
from moban.main import main

0 commit comments

Comments
 (0)