Skip to content

Commit

Permalink
Windows build (#406)
Browse files Browse the repository at this point in the history
* 💚 fix windows build

* 💄 update coding style

* 💚 update mock to unittest.mock
  • Loading branch information
chfw committed Sep 23, 2020
1 parent 111123a commit 0f6b38f
Show file tree
Hide file tree
Showing 17 changed files with 29 additions and 33 deletions.
3 changes: 2 additions & 1 deletion CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

8 contributors
9 contributors
================================================================================

In alphabetical order:
Expand All @@ -9,6 +9,7 @@ In alphabetical order:
* `Charlie Liu <https://github.com/CLiu13>`_
* `John Vandenberg <https://github.com/jayvdb>`_
* `Joshua Chung <https://github.com/seeeturtle>`_
* `pgajdos <https://github.com/pgajdos>`_
* `PRAJWAL M <https://github.com/PrajwalM2212>`_
* `salotz <https://github.com/salotz>`_
* `SerekKiri <https://github.com/SerekKiri>`_
11 changes: 8 additions & 3 deletions moban/core/moban_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging
from collections import defaultdict

from fs.errors import ResourceNotFound
from fs.errors import ResourceNotFound, InvalidCharsInPath
from lml.plugin import PluginManager

from moban import constants, exceptions
Expand Down Expand Up @@ -120,7 +120,12 @@ def number_of_templated_files(self):

def render_to_file(self, template_file, data_file, output_file):
data = self.context.get_data(data_file)
template = self.engine.get_template(template_file)
try:
template = self.engine.get_template(template_file)
except InvalidCharsInPath:
return self.render_string_to_file(
template_file, data_file, output_file
)
try:
template_abs_path = self.template_fs.geturl(
template_file, purpose="fs"
Expand Down Expand Up @@ -204,7 +209,7 @@ def apply_template(self, template_abs_path, template, data, output_file):
# win32 does not work
pass
return flag
except exceptions.FileNotFound:
except (exceptions.FileNotFound, InvalidCharsInPath):
# the template is a string from command line
LOG.info(f"{template_abs_path} is not a file")
self.buffered_writer.write_file_out(output_file, rendered_content)
Expand Down
8 changes: 1 addition & 7 deletions test.bat
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
pip freeze

pytest --cov=moban || goto :error

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

:error
echo Failed with error #%errorlevel%.
exit /b %errorlevel%
pytest --verbosity=3 --cov=moban --doctest-glob=*.rst
3 changes: 1 addition & 2 deletions tests/core/test_engine.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import os
from unittest.mock import patch

import pytest
import fs.path
from mock import patch

from moban.core import ENGINES
from moban.core.definitions import TemplateTarget
Expand Down
2 changes: 1 addition & 1 deletion tests/core/test_moban_factory.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import os
import sys
from unittest.mock import patch

import pytest
import fs.path
from mock import patch
from lml.plugin import PluginInfo

import moban.exceptions as exceptions
Expand Down
5 changes: 3 additions & 2 deletions tests/deprecated/test_handle_requires.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from unittest.mock import patch

import pytest
from mock import patch

from moban.deprecated import GitRequire

Expand Down Expand Up @@ -60,7 +61,7 @@ def test_handle_requires_repos_with_submodule(
fake_git_clone.assert_called_with(
[GitRequire(git_url="https://github.com/my/repo", submodule=True)]
)
assert fake_pip_install.called == False
assert fake_pip_install.called is False


def test_is_repo():
Expand Down
4 changes: 2 additions & 2 deletions tests/deprecated/test_repo.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import unittest
from unittest.mock import patch

import pytest
import fs.path
from mock import patch

from moban.deprecated import GitRequire
from moban.exceptions import NoGitCommand
Expand Down Expand Up @@ -46,7 +46,7 @@ def test_checkout_new(self, fake_repo, local_folder_exists, *_):
depth=2,
)
repo = fake_repo.return_value
assert repo.git.submodule.called == False
assert repo.git.submodule.called is False

def test_checkout_new_with_submodules(
self, fake_repo, local_folder_exists, *_
Expand Down
2 changes: 1 addition & 1 deletion tests/integration_tests/test_command_line_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import sys
import unittest
from shutil import copyfile
from unittest.mock import MagicMock, patch

import fs
import pytest
from mock import MagicMock, patch

from moban.core.definitions import TemplateTarget

Expand Down
3 changes: 2 additions & 1 deletion tests/jinja2/test_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
def test_jinja2_template():
path = fs.path.join("tests", "fixtures", "jinja_tests")
fsys = file_system.get_multi_fs([path])
engine = Engine(fsys)
options = {"extensions": ["test:moban.externals.file_system.exists"]}
engine = Engine(fsys, options)
template = engine.get_template("file_tests.template")
data = dict(test="here")
result = engine.apply_template(template, data, None)
Expand Down
3 changes: 2 additions & 1 deletion tests/mobanfile/test_mobanfile.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from unittest.mock import patch

import pytest
import fs.path
from mock import patch

from moban.core.definitions import TemplateTarget

Expand Down
2 changes: 1 addition & 1 deletion tests/mobanfile/test_templates.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import unittest
from unittest.mock import patch

import pytest
import fs.path
from mock import patch

from moban.core.mobanfile.templates import handle_template

Expand Down
3 changes: 0 additions & 3 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ pytest
pytest-cov
codecov
coverage
mock
yamllint
flake8
black
isort
moban-handlebars
moban-ansible
pypi-mobans-pkg==0.0.12
arrow
jinja2_time
Expand All @@ -18,4 +16,3 @@ jinja2-python-version>=1.1.2
httpfs
collective.checkdocs
Pygments

2 changes: 1 addition & 1 deletion tests/test_file_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import sys
import stat
from shutil import rmtree
from unittest.mock import patch

import fs
import pytest
from mock import patch

from moban.externals import file_system
from moban.exceptions import FileNotFound, UnsupportedPyFS2Protocol
Expand Down
2 changes: 1 addition & 1 deletion tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import sys
import unittest
from shutil import copyfile
from unittest.mock import MagicMock, patch

import fs
import pytest
from mock import MagicMock, patch

import moban.exceptions as exceptions

Expand Down
2 changes: 1 addition & 1 deletion tests/test_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import sys
import filecmp
import unittest
from unittest.mock import patch

import fs
from mock import patch

from moban.main import main
from .utils import Docs
Expand Down
4 changes: 1 addition & 3 deletions tests/test_reporter.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import sys
import unittest

import pytest
from mock import patch
from unittest.mock import patch

from moban.externals import reporter

Expand Down
3 changes: 1 addition & 2 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
import sys
import unittest
from textwrap import dedent
from unittest.mock import patch

import fs
import pytest
from mock import patch
from fs.opener.parse import parse_fs_url

from moban.main import main
Expand Down

0 comments on commit 0f6b38f

Please sign in to comment.