Skip to content

Commit

Permalink
Merge pull request #23 from jazzband/gha
Browse files Browse the repository at this point in the history
Migrate to GitHub Actions.
  • Loading branch information
NickCrews authored May 27, 2022
2 parents 4ae3ada + 4990ad4 commit 0a8ab02
Show file tree
Hide file tree
Showing 13 changed files with 100 additions and 72 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Test

on:
pull_request:
push:
branches:
- master

jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
max-parallel: 5
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10']

steps:
- uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -r tests/requirements.txt
- name: Tox tests
run: |
tox -v
- name: Upload coverage
uses: codecov/codecov-action@v2
with:
name: Python ${{ matrix.python-version }}
fail_ci_if_error: true
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pip-log.txt
# Unit test / coverage reports
.coverage
.tox
nosetests.xml
coverage.xml

#Translations
*.mo
Expand Down
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
repos:
- repo: https://github.com/pycqa/flake8
rev: 4.0.1
hooks:
- id: flake8
12 changes: 0 additions & 12 deletions .travis.yml

This file was deleted.

20 changes: 10 additions & 10 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
import json
import re

try:
import json
except ImportError:
import simplejson as json

import docopt
import pytest

import docopt

RAW_RE = re.compile("#.*$", re.M)


def pytest_collect_file(path, parent):
if path.ext == ".docopt" and path.basename.startswith("test"):
return DocoptTestFile(path, parent)
return DocoptTestFile.from_parent(fspath=path, parent=parent)


def parse_test(raw):
raw = re.compile("#.*$", re.M).sub("", raw).strip()
raw = RAW_RE.sub("", raw).strip()
if raw.startswith('"""'):
raw = raw[3:]

Expand All @@ -39,9 +37,11 @@ def collect(self):
index = 1

for name, doc, cases in parse_test(raw):
name = self.fspath.purebasename
name = "%s(%d)" % (self.fspath.purebasename, index)
for case in cases:
yield DocoptTestItem("%s(%d)" % (name, index), self, doc, case)
yield DocoptTestItem.from_parent(
name=name, parent=self, doc=doc, case=case
)
index += 1


Expand Down
3 changes: 2 additions & 1 deletion docopt.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import inspect


from typing import Any, List, Optional, Tuple, Type, Union, Dict, Callable
from typing import Any, List, Optional, Tuple, Type, Union, Dict, Callable, cast

__all__ = ["docopt", "magic_docopt", "magic", "DocoptExit"]
__version__ = "0.7.2"
Expand Down Expand Up @@ -239,6 +239,7 @@ def fix_repeating_arguments(self) -> "BranchPattern":
if e.value is None:
e.value = []
elif type(e.value) is not list:
e.value = cast(str, e.value)
e.value = e.value.split()
if type(e) is Command or type(e) is Option and e.argcount == 0:
e.value = 0
Expand Down
4 changes: 2 additions & 2 deletions examples/more_magic_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
'STEP2': None}
"""

print(arguments)
print(arguments) # noqa: F821

"""
prints:
False
"""
print(arguments.left)
print(arguments.left) # noqa: F821
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
[wheel]
universal = 1

[flake8]
ignore = E501,E203
24 changes: 3 additions & 21 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,8 @@
import sys
from setuptools import setup
from setuptools.command.test import test as TestCommand

from docopt import __version__


class PyTestCommand(TestCommand):
""" Command to run unit py.test unit tests
"""

def finalize_options(self):
TestCommand.finalize_options(self)
self.test_args = []
self.test_suite = True

def run(self):
import pytest

rcode = pytest.main(self.test_args)
sys.exit(rcode)


setup(
name="docopt-ng",
version=__version__,
Expand All @@ -37,10 +19,10 @@ def run(self):
"Development Status :: 4 - Beta",
"Topic :: Utilities",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"License :: OSI Approved :: MIT License",
],
tests_require=["pytest"],
cmdclass={"test": PyTestCommand},
)
2 changes: 2 additions & 0 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
tox
tox-gh-actions
3 changes: 2 additions & 1 deletion tests/test_docopt.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@ def test_formal_usage():


def test_parse_argv():
def TS(s):
return Tokens(s, error=DocoptExit)
o = [Option("-h"), Option("-v", "--verbose"), Option("-f", "--file", 1)]
TS = lambda s: Tokens(s, error=DocoptExit)
assert parse_argv(TS(""), options=o) == []
assert parse_argv(TS("-h"), options=o) == [Option("-h", None, 0, True)]
assert parse_argv(TS("-h --verbose"), options=o) == [Option("-h", None, 0, True), Option("-v", "--verbose", 0, True)]
Expand Down
28 changes: 14 additions & 14 deletions tests/test_docopt_ng.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import pytest
import docopt
from docopt import DocoptExit, DocoptLanguageError, Option, Argument, Command, OptionsShortcut, Required, NotRequired, parse_argv, Tokens
from docopt import DocoptExit, DocoptLanguageError, Option, Argument, parse_argv, Tokens
from pytest import raises
from docopt import magic
from docopt import magic_docopt
from docopt import docopt as user_provided_alias_containing_magic


def test_docopt_ng_more_magic_spellcheck_and_expansion():
def TS(s):
return Tokens(s, error=DocoptExit)
o = [Option("-h"), Option("-v", "--verbose"), Option(None, "--file", 1)]
TS = lambda s: Tokens(s, error=DocoptExit)
assert parse_argv(TS(""), options=o) == []
assert parse_argv(TS("-h"), options=o) == [Option("-h", None, 0, True)]
assert parse_argv(TS("-V"), options=o, more_magic=True) == [Option("-v", "--verbose", 0, True)]
Expand Down Expand Up @@ -42,12 +43,12 @@ def test_docopt_ng_as_magic_docopt_more_magic_global_arguments_and_dot_access():
global arguments
magic_docopt(doc, "-v file.py")
assert arguments == {"-v": True, "-q": False, "-r": False, "--help": False, "FILE": "file.py", "INPUT": None, "OUTPUT": None}
assert arguments.v == True
assert arguments.v
assert arguments.FILE == "file.py"
arguments = None
magic(doc, "-v file.py")
assert arguments == {"-v": True, "-q": False, "-r": False, "--help": False, "FILE": "file.py", "INPUT": None, "OUTPUT": None}
assert arguments.v == True
assert arguments.v
assert arguments.FILE == "file.py"
arguments = None
user_provided_alias_containing_magic(doc, "-v file.py")
Expand All @@ -70,9 +71,9 @@ def test_docopt_ng_more_magic_no_make_global_arguments_if_assigned():
global arguments
arguments = None
opts = magic_docopt(doc, argv="-v file.py")
assert arguments == None
assert arguments is None
assert opts == {"-v": True, "-q": False, "-r": False, "--help": False, "FILE": "file.py", "INPUT": None, "OUTPUT": None}
assert opts.v == True
assert opts.v
assert opts.FILE == "file.py"


Expand All @@ -91,13 +92,12 @@ def test_docopt_ng_more_magic_global_arguments_and_dot_access():
global arguments
docopt.docopt(doc, "-v file.py", more_magic=True)
assert arguments == {"-v": True, "-q": False, "-r": False, "--help": False, "FILE": "file.py", "INPUT": None, "OUTPUT": None}
assert arguments.v == True
assert arguments.v
assert arguments.FILE == "file.py"
arguments = None
docopt.docopt(doc.replace("FILE", "<FILE>"), "-v", more_magic=True)
str_arguments = str(arguments)
assert arguments == {"-v": True, "-q": False, "-r": False, "--help": False, "<FILE>": None, "INPUT": None, "OUTPUT": None}
assert arguments.FILE == None
assert arguments.FILE is None

with raises(DocoptExit):
docopt.docopt(doc, "-v input.py output.py")
Expand All @@ -113,7 +113,7 @@ def test_docopt_ng__doc__if_no_doc():
assert docopt.docopt() == {"--long": ""}
__doc__, sys.argv = "usage:\n\tprog -l <a>\noptions:\n\t-l <a>\n", [None, "-l", ""]
assert docopt.docopt() == {"-l": ""}
__doc__, sys.argv = None, [None, "-l", ""]
__doc__, sys.argv = None, [None, "-l", ""] # noqa: F841
with raises(DocoptLanguageError):
docopt.docopt()

Expand All @@ -125,14 +125,14 @@ def test_docopt_ng_negative_float():

def test_docopt_ng_doubledash_version():
with pytest.raises(SystemExit) as pytest_wrapped_e:
args = docopt.docopt("usage: prog", version=1, argv="prog --version")
docopt.docopt("usage: prog", version=1, argv="prog --version")
assert pytest_wrapped_e.type == SystemExit


def test_docopt_ng__doc__if_no_doc_indirection():
import sys

__doc__, sys.argv = "usage: prog --long=<a>", [None, "--long="]
__doc__, sys.argv = "usage: prog --long=<a>", [None, "--long="] # noqa: F841

def test_indirect():
return docopt.docopt()
Expand Down Expand Up @@ -169,6 +169,6 @@ def test_docopt_ng_dot_access_with_dash():
"INPUT": None,
"OUTPUT": None,
}
assert arguments.v == True
assert arguments.v
assert arguments.FILE == "file.py"
assert arguments.dash_arg == True
assert arguments.dash_arg
26 changes: 16 additions & 10 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
[tox]

envlist = py36, py37
skipsdist = true
usedevelop = true
minversion = 1.8
envlist = py{37,38,39,310}

[testenv]
commands =
pytest --cov-report term-missing --cov-report xml --cov=docopt --cov=docopt --mypy --mypy-ignore-missing-imports ./tests

commands = pytest --cov-report term-missing --cov=docopt --cov=docopt --mypy --mypy-ignore-missing-imports ./tests
flake8 --ignore=E501,E203 docopt.py
codecov -t d77e0aec-f57f-4f33-9400-cd3b3919ffc8
deps =
pytest
pytest-mypy
pytest-cov

deps = pytest
flake8
codecov
pytest-mypy
pytest-cov
[gh-actions]
python =
3.7: py37
3.8: py38
3.9: py39
3.10: py310

0 comments on commit 0a8ab02

Please sign in to comment.