Merge pull request #2539 from Andrew-Chen-Wang/ci

This commit is contained in:
Bruno Alla 2020-04-17 11:34:50 +01:00 committed by GitHub
commit f01ff95c51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 74 additions and 20 deletions

View File

@ -172,8 +172,12 @@ def test_black_passes(cookies, context_override):
pytest.fail(e.stdout.decode()) pytest.fail(e.stdout.decode())
def test_travis_invokes_pytest(cookies, context): @pytest.mark.parametrize(
context.update({"ci_tool": "Travis"}) ["use_docker", "expected_test_script"],
[("n", "pytest"), ("y", "docker-compose -f local.yml run django pytest"),],
)
def test_travis_invokes_pytest(cookies, context, use_docker, expected_test_script):
context.update({"ci_tool": "Travis", "use_docker": use_docker})
result = cookies.bake(extra_context=context) result = cookies.bake(extra_context=context)
assert result.exit_code == 0 assert result.exit_code == 0
@ -183,13 +187,21 @@ def test_travis_invokes_pytest(cookies, context):
with open(f"{result.project}/.travis.yml", "r") as travis_yml: with open(f"{result.project}/.travis.yml", "r") as travis_yml:
try: try:
assert yaml.load(travis_yml, Loader=yaml.FullLoader)["script"] == ["pytest"] yml = yaml.load(travis_yml, Loader=yaml.FullLoader)["jobs"]["include"]
assert yml[0]["script"] == ["flake8"]
assert yml[1]["script"] == [expected_test_script]
except yaml.YAMLError as e: except yaml.YAMLError as e:
pytest.fail(e) pytest.fail(str(e))
def test_gitlab_invokes_flake8_and_pytest(cookies, context): @pytest.mark.parametrize(
context.update({"ci_tool": "Gitlab"}) ["use_docker", "expected_test_script"],
[("n", "pytest"), ("y", "docker-compose -f local.yml run django pytest"),],
)
def test_gitlab_invokes_flake8_and_pytest(
cookies, context, use_docker, expected_test_script
):
context.update({"ci_tool": "Gitlab", "use_docker": use_docker})
result = cookies.bake(extra_context=context) result = cookies.bake(extra_context=context)
assert result.exit_code == 0 assert result.exit_code == 0
@ -201,7 +213,7 @@ def test_gitlab_invokes_flake8_and_pytest(cookies, context):
try: try:
gitlab_config = yaml.load(gitlab_yml, Loader=yaml.FullLoader) gitlab_config = yaml.load(gitlab_yml, Loader=yaml.FullLoader)
assert gitlab_config["flake8"]["script"] == ["flake8"] assert gitlab_config["flake8"]["script"] == ["flake8"]
assert gitlab_config["pytest"]["script"] == ["pytest"] assert gitlab_config["pytest"]["script"] == [expected_test_script]
except yaml.YAMLError as e: except yaml.YAMLError as e:
pytest.fail(e) pytest.fail(e)

View File

@ -22,8 +22,21 @@ flake8:
pytest: pytest:
stage: test stage: test
image: python:3.7 image: python:3.7
{% if cookiecutter.use_docker == 'y' -%}
tags: tags:
- docker - docker
services:
- docker
before_script:
- docker-compose -f local.yml build
# Ensure celerybeat does not crash due to non-existent tables
- docker-compose -f local.yml run --rm django python manage.py migrate
- docker-compose -f local.yml up -d
script:
- docker-compose -f local.yml run django pytest
{%- else %}
tags:
- python
services: services:
- postgres:11 - postgres:11
variables: variables:
@ -34,4 +47,5 @@ pytest:
script: script:
- pytest - pytest
{%- endif %}

View File

@ -1,17 +1,45 @@
dist: xenial dist: xenial
language: python
python:
- "3.8"
services: services:
- postgresql - {% if cookiecutter.use_docker == 'y' %}docker{% else %}postgresql{% endif %}
before_install: jobs:
include:
- name: "Linter"
before_script:
- pip install -q flake8
script:
- "flake8"
- name: "Django Test"
{%- if cookiecutter.use_docker == 'y' %}
before_script:
- docker-compose -v
- docker -v
- docker-compose -f local.yml build
# Ensure celerybeat does not crash due to non-existent tables
- docker-compose -f local.yml run --rm django python manage.py migrate
- docker-compose -f local.yml up -d
script:
- "docker-compose -f local.yml run django pytest"
after_failure:
- docker-compose -f local.yml logs
{%- else %}
before_install:
- sudo apt-get update -qq - sudo apt-get update -qq
- sudo apt-get install -qq build-essential gettext python-dev zlib1g-dev libpq-dev xvfb - sudo apt-get install -qq build-essential gettext python-dev zlib1g-dev libpq-dev xvfb
- sudo apt-get install -qq libjpeg8-dev libfreetype6-dev libwebp-dev - sudo apt-get install -qq libjpeg8-dev libfreetype6-dev libwebp-dev
- sudo apt-get install -qq graphviz-dev python-setuptools python3-dev python-virtualenv python-pip - sudo apt-get install -qq graphviz-dev python-setuptools python3-dev python-virtualenv python-pip
- sudo apt-get install -qq firefox automake libtool libreadline6 libreadline6-dev libreadline-dev - sudo apt-get install -qq firefox automake libtool libreadline6 libreadline6-dev libreadline-dev
- sudo apt-get install -qq libsqlite3-dev libxml2 libxml2-dev libssl-dev libbz2-dev wget curl llvm - sudo apt-get install -qq libsqlite3-dev libxml2 libxml2-dev libssl-dev libbz2-dev wget curl llvm
language: python language: python
python: python:
- "3.8" - "3.8"
install: install:
- pip install -r requirements/local.txt - pip install -r requirements/local.txt
script: script:
- "pytest" - "pytest"
{%- endif %}