Skip to content

Commit ed54484

Browse files
committed
✨ Set up CI with Azure Pipelines on windows and macos, resolve #122. :wheel_chair: skip the file permission related tests for now. #141
1 parent 1dcd10c commit ed54484

21 files changed

+94
-15
lines changed

.azure-pipelines-steps-macos.yml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
steps:
2+
- task: UsePythonVersion@0
3+
displayName: 'Use Python 3.x'
4+
- script: |
5+
python -m pip install --upgrade pip setuptools wheel
6+
pip install -r requirements.txt
7+
pip install -r tests/requirements.txt
8+
displayName: 'Setup dependencies'
9+
- script: |
10+
make
11+
displayName: 'Run tests'

.azure-pipelines-steps.yml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
steps:
2+
- task: UsePythonVersion@0
3+
displayName: 'Use Python 3.x'
4+
- script: |
5+
python -m pip install --upgrade pip setuptools wheel
6+
pip install -r requirements.txt
7+
pip install -r tests\requirements.txt
8+
displayName: 'Setup dependencies'
9+
- script: |
10+
test.bat
11+
displayName: 'Run tests'

.isort.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[settings]
22
line_length=79
3-
known_first_party=lml, jinja2, ruamel.yaml
3+
known_first_party=lml, jinja2, ruamel.yaml, mock, nose
44
indent=' '
55
multi_line_output=3
66
length_sort=1

README.rst

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ moban - 模板 Yet another jinja2 cli command for static text generation
55
.. image:: https://api.travis-ci.org/moremoban/moban.svg?branch=master
66
:target: http://travis-ci.org/moremoban/moban
77

8+
.. image:: GET https://dev.azure.com/moremoban/moban/_apis/build/repos/{repoType}/badge?api-version=5.0-preview.2
9+
:target: https://dev.azure.com/moremoban/moban/_build?definitionId=1&_a=summary
10+
811
.. image:: https://codecov.io/gh/moremoban/moban/branch/master/graph/badge.svg
912
:target: https://codecov.io/gh/moremoban/moban
1013

azure-pipelines.yml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Starter pipeline
2+
# Start with a minimal pipeline that you can customize to build and deploy your code.
3+
# Add steps that build, run tests, deploy, and more:
4+
# https://aka.ms/yaml
5+
jobs:
6+
- job: 'Windows'
7+
pool:
8+
vmImage: vs2017-win2016
9+
steps:
10+
- template: '.azure-pipelines-steps.yml'
11+
- job: 'MacOS'
12+
pool:
13+
vmImage: macOS-10.13
14+
steps:
15+
- template: '.azure-pipelines-steps-macos.yml'

test.bat

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ pip freeze
33
cd tests\moban-mako
44
python setup.py install
55
cd ..\..\
6-
nosetests --with-coverage --with-doctest --doctest-extension=.rst --cover-package=moban --cover-package=tests
7-
flake8 . --exclude=.moban.d --ignore=E203,E121,E123,E126,E226,E24,E704,W503,W504
6+
nosetests --with-coverage --cover-package=moban --cover-package=tests
7+
flake8 . --exclude=docs --exclude=.moban.d --ignore=E203,E121,E123,E126,E226,E24,E704,W503,W504

tests/test_context.py

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

33
from nose.tools import eq_
4+
45
from moban.plugins import Context
56

67

tests/test_copier.py

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from mock import patch
55
from nose.tools import eq_
6+
67
from moban.copier import Copier
78
from moban.mobanfile import handle_copy
89

tests/test_docs.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
import sys
33

44
from mock import patch
5-
from moban.main import main
65
from nose.tools import eq_
76

7+
from moban.main import main
8+
89

910
class TestTutorial:
1011
def setUp(self):
@@ -88,7 +89,8 @@ def test_level_7(self):
8889
def test_level_8(self):
8990
expected = "it is a test\n"
9091
folder = "level-8-pass-a-folder-full-of-templates"
91-
self._raw_moban(["moban"], folder, expected, "templated-folder/my")
92+
check_file = os.path.join("templated-folder", "my")
93+
self._raw_moban(["moban"], folder, expected, check_file)
9294

9395
def test_level_9(self):
9496
expected = "pypi-mobans: moban dependency as pypi package"

tests/test_engine.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import os
22

3+
from mock import patch
34
from lml.plugin import PluginInfo
5+
from nose.tools import eq_, raises
46

57
import moban.exceptions as exceptions
6-
from mock import patch
7-
from nose.tools import eq_, raises
88
from moban.plugins import (
99
ENGINES,
1010
Context,
@@ -13,6 +13,8 @@
1313
)
1414
from moban.jinja2.engine import Engine
1515

16+
USER_HOME = os.path.join("user", "home", ".moban", "repos")
17+
1618

1719
@PluginInfo("library", tags=["testmobans"])
1820
class TestPypkg:
@@ -27,12 +29,12 @@ def test_expand_pypi_dir():
2729
assert os.path.exists(directory)
2830

2931

30-
@patch("moban.utils.get_moban_home", return_value="/user/home/.moban/repos")
32+
@patch("moban.utils.get_moban_home", return_value=USER_HOME)
3133
@patch("os.path.exists", return_value=True)
3234
def test_expand_repo_dir(_, __):
3335
dirs = list(expand_template_directories("git_repo:template"))
3436

35-
expected = ["/user/home/.moban/repos/git_repo/template"]
37+
expected = [os.path.join(USER_HOME, "git_repo", "template")]
3638
eq_(expected, dirs)
3739

3840

tests/test_filter_github.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from nose.tools import eq_
2+
23
from moban.jinja2.filters.github import github_expand
34

45

tests/test_filter_repr.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from nose.tools import eq_
2+
23
from moban.jinja2.filters.repr import repr as repr_function
34

45

tests/test_hash_store.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import os
2+
import sys
23

34
from moban.hashstore import HashStore
5+
from nose import SkipTest
46

57

68
class TestHashStore:
@@ -13,7 +15,8 @@ def setUp(self):
1315
)
1416

1517
def tearDown(self):
16-
os.unlink(".moban.hashes")
18+
if os.path.exists(".moban.hashes"):
19+
os.unlink(".moban.hashes")
1720

1821
def test_simple_use_case(self):
1922
hs = HashStore()
@@ -76,6 +79,8 @@ def test_dest_file_file_permision_changed(self):
7679
Save as above, but this time,
7780
the generated file had file permision change
7881
"""
82+
if sys.platform == 'win32':
83+
raise SkipTest('No actual chmod on windows')
7984
hs = HashStore()
8085
flag = hs.is_file_changed(*self.fixture)
8186
if flag:

tests/test_jinja2_engine.py

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

33
from nose.tools import eq_
4+
45
from moban.jinja2.engine import Engine
56

67

tests/test_jinja2_extensions.py

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

33
from nose.tools import eq_
4+
45
from moban.plugins import BaseEngine
56
from moban.jinja2.engine import Engine
67
from moban.jinja2.extensions import jinja_global

tests/test_main.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
import sys
33
from shutil import copyfile
44

5-
import moban.exceptions as exceptions
65
from mock import patch
76
from nose.tools import raises, assert_raises
87

8+
import moban.exceptions as exceptions
9+
910

1011
class TestException:
1112
def setUp(self):

tests/test_reporter.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import sys
22

3-
import moban.reporter as reporter
43
from mock import patch
54
from nose.tools import eq_
65

6+
import moban.reporter as reporter
7+
78
PY2 = sys.version_info[0] == 2
89
if PY2:
910
from StringIO import StringIO

tests/test_template.py

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

33
from mock import patch
4+
45
from moban.plugins import BaseEngine
56
from moban.jinja2.engine import Engine
67

tests/test_text_filter.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from nose.tools import eq_
2+
23
from moban.jinja2.filters.text import split_length
34

45

tests/test_utils.py

+22-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import os
2+
import sys
23
import stat
34
from shutil import rmtree
45

56
from mock import patch
67
from nose.tools import eq_, raises
8+
from nose import SkipTest
79
from moban.utils import (
810
mkdir_p,
911
get_repo_name,
@@ -25,6 +27,8 @@ def create_file(test_file, permission):
2527

2628

2729
def test_file_permission_copy():
30+
if sys.platform == 'win32':
31+
raise SkipTest('No actual chmod on windows')
2832
test_source = "test_file_permission_copy1"
2933
test_dest = "test_file_permission_copy2"
3034
create_file(test_source, 0o046)
@@ -44,6 +48,8 @@ def test_file_permissions_file_not_found():
4448

4549

4650
def test_file_permission_copy_symlink():
51+
if sys.platform == 'win32':
52+
raise SkipTest('No symlink on windows')
4753
test_source = "test_file_permission_copy1"
4854
test_dest = "test_file_permission_copy2"
4955
test_symlink = "test_file_permission_symlink"
@@ -92,15 +98,28 @@ def test_expand_dir():
9298
file_list = [("template-tests", "abc", "abc")]
9399
template_dirs = [os.path.join("tests", "fixtures")]
94100
results = list(expand_directories(file_list, template_dirs))
95-
expected = [("template-tests/a.jj2", "abc", "abc/a")]
101+
expected = [
102+
(
103+
os.path.join("template-tests", "a.jj2"),
104+
"abc",
105+
os.path.join("abc", "a"),
106+
)
107+
]
96108
eq_(results, expected)
97109

98110

99111
def test_get_template_path():
100-
temp_dirs = ["tests/fixtures/template-tests", "tests/abc", "tests/abc"]
112+
temp_dirs = [
113+
os.path.join("tests", "fixtures", "template-tests"),
114+
os.path.join("tests", "abc"),
115+
os.path.join("tests", "abc"),
116+
]
101117
template = "a.jj2"
102118
template_path = get_template_path(temp_dirs, template)
103-
expected = os.path.join(os.getcwd(), "tests/fixtures/template-tests/a.jj2")
119+
expected = os.path.join(
120+
os.getcwd(),
121+
os.path.join("tests", "fixtures", "template-tests", "a.jj2"),
122+
)
104123
eq_(template_path, expected)
105124

106125

tests/test_yaml_loader.py

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

33
from nose.tools import eq_, raises
4+
45
from moban.utils import open_yaml
56

67

0 commit comments

Comments
 (0)