Skip to content

Commit

Permalink
un-silenced windows build (#251)
Browse files Browse the repository at this point in the history
* 🔬 let's start the test first. #117

* 🐛 fix import error

* 🔬 show true failures on windows

* 🐛fix samefile not available on windows. python-rope/ropevim#66

* 🐛 fix windows os path problem

* 💚 make windows ci work

* 💚 final touch on the windows ci failure

* 💄 beautify the code using black and isort

* 📰 show sub folder on windows

* 🐛 jinja2 does not windows style file path

* 💚 fix last failure...sigh..

* 📚 update change log
  • Loading branch information
chfw authored Mar 8, 2019
1 parent 057cfbd commit 651e448
Show file tree
Hide file tree
Showing 20 changed files with 107 additions and 45 deletions.
3 changes: 2 additions & 1 deletion .moban.cd/changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ releases:
- "`#234`: Define template parameters on the fly inside `targets` section"
- "`#180`: No longer two statistics will be shown in v0.4.x. legacy copy targets are injected into a normal targets. cli target is made a clear priority."
- "`#62`: select a group target to run"
date: unreleased
- "`#244`: version 0.4.2 is first version which would work perfectly on windows since 17 Nov 2018. Note that: file permissions are not used on windows. Why the date? because samefile is not avaiable on windows, causing unit tests to fail hence it lead to my conclusion that moban version between 17 Nov 2018 and March 2019 wont work well on Windows."
date: 08.03.2019
version: 0.4.2
- changes:
- action: Added
Expand Down
8 changes: 7 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Change log
================================================================================

0.4.2 - unreleased
0.4.2 - 08.03.2019
--------------------------------------------------------------------------------

Added
Expand All @@ -14,6 +14,12 @@ Added
normal targets. cli target is made a clear priority.
#. `#62 <https://github.com/moremoban/moban/issues/62>`_: select a group target
to run
#. `#244 <https://github.com/moremoban/moban/issues/244>`_: version 0.4.2 is
first version which would work perfectly on windows since 17 Nov 2018. Note
that: file permissions are not used on windows. Why the date? because
samefile is not avaiable on windows, causing unit tests to fail hence it lead
to my conclusion that moban version between 17 Nov 2018 and March 2019 wont
work well on Windows.

0.4.1 - 28.02.2019
--------------------------------------------------------------------------------
Expand Down
4 changes: 0 additions & 4 deletions docs/level-11-use-handlebars/b.output

This file was deleted.

7 changes: 0 additions & 7 deletions docs/level-14-custom-data-loader/b.output

This file was deleted.

9 changes: 0 additions & 9 deletions docs/level-6-complex-configuration/a.output

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
please
17 changes: 7 additions & 10 deletions moban/jinja2/tests/files.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
from os.path import (
isabs,
isdir,
exists,
isfile,
islink,
ismount,
lexists,
samefile,
)
import sys
from os.path import isabs, isdir, exists, isfile, islink, ismount, lexists

from moban.jinja2.extensions import jinja_tests

if sys.platform == "win32":
from moban.jinja2.tests.win32 import samefile
else:
from os.path import samefile

jinja_tests(
is_dir=isdir,
directory=isdir,
Expand Down
5 changes: 5 additions & 0 deletions moban/jinja2/tests/win32.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from os.path import normcase, normpath


def samefile(file1, file2):
return normcase(normpath(file1)) == normcase(normpath(file2))
7 changes: 6 additions & 1 deletion moban/mobanfile/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ def _list_dir_files(source, actual_source_path, dest):
for file_name in os.listdir(actual_source_path):
real_src_file = os.path.join(actual_source_path, file_name)
if os.path.isfile(real_src_file):
src_file_under_dir = os.path.join(source, file_name)
# 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)
# but actually it breaks windows instead.
src_file_under_dir = '%s/%s' % (source, file_name)

dest_file_under_dir = os.path.join(dest, file_name)
template_type = _get_template_type(src_file_under_dir)
yield (src_file_under_dir, dest_file_under_dir, template_type)
Expand Down
3 changes: 2 additions & 1 deletion moban/plugins/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,9 @@ def expand_template_directories(dirs):


def expand_template_directory(directory):
log.debug("Expanding %s..." % directory)
translated_directory = None
if ":" in directory:
if ":" in directory and directory[1] != ":":
library_or_repo_name, relative_path = directory.split(":")
potential_repo_path = os.path.join(
repo.get_moban_home(), library_or_repo_name
Expand Down
4 changes: 2 additions & 2 deletions moban/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ def file_permissions_copy(source, dest):


def file_permissions(afile):
if sys.platform == "win32":
return "no-permission-support"
if not os.path.exists(afile):
raise exceptions.FileNotFound(afile)
if sys.platform == "win32":
return 0
return stat.S_IMODE(os.stat(afile).st_mode)


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

nosetests --with-coverage --cover-package=moban --cover-package=tests
flake8 . --exclude=docs,.moban.d --ignore=E203,E121,E123,E126,E226,E24,E704,W503,W504
nosetests --with-coverage --cover-package=moban --cover-package=tests && flake8 . --exclude=docs,.moban.d --ignore=E203,E121,E123,E126,E226,E24,E704,W503,W504
12 changes: 7 additions & 5 deletions tests/mobanfile/test_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_listing_dir(self):
expected = [
(
"copier-directory/level1-file1",
"/tmp/copy-a-directory/level1-file1",
os.path.join("/tmp/copy-a-directory", "level1-file1"),
None,
)
]
Expand All @@ -49,13 +49,15 @@ def test_listing_dir_recusively(self):
)
expected = [
(
"copier-directory/copier-sample-dir/file1",
"/tmp/copy-a-directory/copier-sample-dir/file1",
os.path.join("copier-directory", "copier-sample-dir", "file1"),
os.path.join(
"/tmp/copy-a-directory", "copier-sample-dir", "file1"
),
None,
),
(
"copier-directory/level1-file1",
"/tmp/copy-a-directory/level1-file1",
os.path.join("copier-directory", "level1-file1"),
os.path.join("/tmp/copy-a-directory", "level1-file1"),
None,
),
]
Expand Down
6 changes: 6 additions & 0 deletions tests/regression-pack/symbolic-link-gets-junk/.moban.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
configuration:
template_dir:
- .
targets:
- a.output: symbolic-link
- b.output: sym-link-to-file
3 changes: 2 additions & 1 deletion tests/test_copy_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ def setUp(self):

def test_get_template(self):
template_content = self.engine.get_template("copier-test01.csv")
eq_("test 01\n", template_content)
# remove '\r' for windows
eq_("test 01\n", template_content.replace("\r", ""))

def test_get_template_from_string(self):
test_content = "simply forwarded"
Expand Down
5 changes: 5 additions & 0 deletions tests/test_hash_store.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import os
import sys

from nose import SkipTest

from moban.hashstore import HashStore

Expand Down Expand Up @@ -77,6 +80,8 @@ def test_dest_file_file_permision_changed(self):
Save as above, but this time,
the generated file had file permision change
"""
if sys.platform == "win32":
raise SkipTest("No file permission check on windows")
hs = HashStore()
flag = hs.is_file_changed(*self.fixture)
if flag:
Expand Down
52 changes: 52 additions & 0 deletions tests/test_regression_pack.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import os
import sys
from textwrap import dedent

from mock import patch
from nose import SkipTest
from nose.tools import eq_

from moban.main import main


def custom_dedent(long_texts):
refined = dedent(long_texts)
if refined.startswith("\n"):
refined = refined[1:]
return refined


class TestTutorial:
def setUp(self):
self.current = os.getcwd()

def test_symbolic_link_on_windows(self):
if sys.platform != "win32":
raise SkipTest("No need to test on linux nor macos")

expected = "/tmp"

folder = "symbolic-link-gets-junk"
self._raw_moban(["moban"], folder, expected, "a.output")

def _moban(self, folder, expected):
args = ["moban", "-c", "data.yml", "-t", "a.template"]
self._raw_moban(args, folder, expected, "moban.output")

def _raw_moban(self, args, folder, expected, output):
os.chdir(os.path.join("tests", "regression-pack", folder))
with patch.object(sys, "argv", args):
main()
_verify_content(output, expected)
os.unlink(output)

def tearDown(self):
if os.path.exists(".moban.hashes"):
os.unlink(".moban.hashes")
os.chdir(self.current)


def _verify_content(file_name, expected):
with open(file_name, "r") as f:
content = f.read()
eq_(content, expected)

0 comments on commit 651e448

Please sign in to comment.