Skip to content
This repository has been archived by the owner on Jan 22, 2024. It is now read-only.

Commit

Permalink
Merge pull request #34 from Rainist/feature/makefile
Browse files Browse the repository at this point in the history
Makefile, travis 개선
  • Loading branch information
winterjung authored Jun 14, 2019
2 parents dc01402 + 3d9340d commit e3e7877
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 12 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ sudo: required

language: python

dist:
- xenial
dist: xenial

python:
- "3.7"
Expand Down
31 changes: 31 additions & 0 deletions tests/test_makefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,35 @@ def test_makefile_total_lines(cookies, context, black, pipenv, mypy):
expected = 27
expected -= 2 if black == 'n' else 0
expected -= 1 if mypy == 'do not use' else 0
expected += 4 if pipenv == 'y' else 0
assert len(lines) == expected


@pytest.mark.parametrize('black', ['y', 'n'])
@pytest.mark.parametrize('pipenv', ['y', 'n'])
@pytest.mark.parametrize('mypy', ['do not use', 'beginner', 'expert'])
def test_makefile_total_section(cookies, context, black, pipenv, mypy):
ctx = context(black=black, pipenv=pipenv, mypy=mypy)
result = cookies.bake(extra_context=ctx)

makefile = result.project.join('Makefile')
content = makefile.read()
sections = content.strip().split('\n\n')

expected = 8
expected -= 1 if pipenv == 'n' else 0
assert len(sections) == expected


@pytest.mark.parametrize('pipenv', ['y', 'n'])
def test_makefile_phony(cookies, context, pipenv):
ctx = context(pipenv=pipenv)
result = cookies.bake(extra_context=ctx)

makefile = result.project.join('Makefile')
lines = makefile.readlines()
phony = lines[0]

expected = 8
expected -= 1 if pipenv == 'n' else 0
assert len(phony.split(' ')) == expected
43 changes: 43 additions & 0 deletions tests/test_travis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import pytest


@pytest.mark.parametrize('version', ['3.7', '3.6'])
@pytest.mark.parametrize('pipenv', ['y', 'n'])
def test_travis_total_lines(cookies, context, version, pipenv):
"""
We expect .travis.yml has below content
```
1 sudo: required
2
3 language: python
4
5 install:
6 - make
```
"""
ctx = context(version=version, pipenv=pipenv)
result = cookies.bake(extra_context=ctx)

makefile = result.project.join('.travis.yml')
lines = makefile.readlines(cr=False)

expected = 32
expected -= 2 if version == '3.6' else 0
expected -= 6 if pipenv == 'n' else 0
assert len(lines) == expected


@pytest.mark.parametrize('version', ['3.7', '3.6'])
@pytest.mark.parametrize('pipenv', ['y', 'n'])
def test_travis_total_section(cookies, context, version, pipenv):
ctx = context(version=version, pipenv=pipenv)
result = cookies.bake(extra_context=ctx)

makefile = result.project.join('.travis.yml')
content = makefile.read()
sections = content.strip().split('\n\n')

expected = 10
expected -= 1 if version == '3.6' else 0
expected -= 1 if pipenv == 'n' else 0
assert len(sections) == expected
9 changes: 6 additions & 3 deletions {{cookiecutter.project_slug}}/.travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ language: python

{%- if cookiecutter.python_version == "3.7" %}

dist:
- xenial
dist: xenial
{%- endif %}

python:
Expand All @@ -30,7 +29,6 @@ install:
- make

script:

{%- if cookiecutter.use_pipenv|lower != 'n' %}
- pipenv run make check
- pipenv run make test
Expand All @@ -40,4 +38,9 @@ script:
{%- endif %}

after_success:
{%- if cookiecutter.use_pipenv|lower != 'n' %}
- pipenv run make coverage
{%- else %}
- make coverage
{%- endif %}
- bash < (curl -s https://codecov.io/bash)
11 changes: 9 additions & 2 deletions {{cookiecutter.project_slug}}/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: init check format test coverage htmlcov
.PHONY: init check format test coverage htmlcov{% if cookiecutter.use_pipenv|lower != 'n' %} requirements{% endif %}

init:
{%- if cookiecutter.use_pipenv|lower != 'n' %}
Expand Down Expand Up @@ -29,9 +29,16 @@ test:
python -m pytest

coverage:
python -m pytest --cov {{ cookiecutter.package_name }} --cov-report term
python -m pytest --cov {{ cookiecutter.package_name }} --cov-report term --cov-report xml

htmlcov:
python -m pytest --cov {{ cookiecutter.package_name }} --cov-report html
rm -rf /tmp/htmlcov && mv htmlcov /tmp/
open /tmp/htmlcov/index.html

{%- if cookiecutter.use_pipenv|lower != 'n' %}

requirements:
pipenv lock -r > requirements.txt
pipenv lock -dr > requirements-dev.txt
{%- endif %}
10 changes: 5 additions & 5 deletions {{cookiecutter.project_slug}}/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]
isort = "*"
isort = "4.3.20"
{%- if cookiecutter.use_black|lower != 'n' %}
black = "==19.3b0"
{%- endif %}
pylint = "*"
pylint = "2.3.1"
{%- if cookiecutter.use_mypy|lower != 'do not use' %}
mypy = "*"
mypy = "0.701"
{%- endif %}
pytest = "*"
pytest-cov = "*"
pytest = "4.6.3"
pytest-cov = "2.7.1"

[packages]

Expand Down

0 comments on commit e3e7877

Please sign in to comment.