Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup #31

Merged
merged 14 commits into from
May 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,15 @@ jobs:
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
python -m pip install -e .[dev]

- name: Tox tests
- name: Run tests
run: |
tox -v
pytest

- name: Upload coverage
uses: codecov/codecov-action@v2
Expand All @@ -45,19 +44,19 @@ jobs:
- test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v3
with:
python-version: "3.10"

- name: Install dependencies
run: |
python -m pip install -U pip
python -m pip install -U twine build
python -m pip install --upgrade pip
python -m pip install --upgrade twine build

- name: Build package
run: |
Expand Down
13 changes: 0 additions & 13 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,4 @@ pip-log.txt

# Unit test / coverage reports
.coverage
.tox
coverage.xml

#Translations
*.mo

#Mr Developer
.mr.developer.cfg

# Sphinx
docs/_*

# jython
*$py.class
1 change: 0 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
include README.md LICENSE-MIT
recursive-include examples *.py
23 changes: 15 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
[![Jazzband](https://jazzband.co/static/img/badge.svg)](https://jazzband.co/)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

**docopt-ng** is a fork of the original docopt, maintained by the
[jazzband](https://jazzband.co/) project.
**docopt-ng** is a fork of the [original docopt](https://github.com/docopt/docopt), now maintained by the
[jazzband](https://jazzband.co/) project. Now with maintenance, typehints, and complete test coverage!

**docopt-ng** helps you create beautiful command-line interfaces *magically*:

Expand Down Expand Up @@ -326,13 +326,20 @@ out, read the source if in doubt.
# Development

We would *love* to hear what you think about **docopt-ng** on our
[issues page](https://github.com/jazzband/docopt-ng/issues)
[issues page](https://github.com/jazzband/docopt-ng/issues). Make pull requests, report bugs, and suggest ideas.

Make pull requests, report bugs, suggest ideas and discuss
**docopt-ng**.
To setup your dev environment, fork this repo, clone it locally, and then create
a dev environment:

## Testing
python -m venv .venv
source .venv/bin/activate

You can run unit tests using the command:
Then install this package as editable, as well as dev requirements.

tox -v
python -m pip install -e .[dev]

Useful testing, linting, and formatting commands:

pytest
black **/*.py
flake8 **.*.py
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
[build-system]
requires = ['setuptools', 'wheel']

[tool.pytest.ini_options]
addopts = "--cov-report term-missing --cov-report xml --cov=docopt --mypy"
testpaths = [
"./tests",
]
6 changes: 0 additions & 6 deletions scripts/linter

This file was deleted.

35 changes: 14 additions & 21 deletions conftest.py → tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,48 +1,41 @@
import json
from pathlib import Path
import re

import docopt
import pytest


RAW_RE = re.compile("#.*$", re.M)
def pytest_collect_file(file_path: Path, path, parent):
if file_path.suffix == ".docopt" and file_path.stem.startswith("test"):
return DocoptTestFile.from_parent(path=file_path, parent=parent)


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


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

for fixture in raw.split('r"""'):
name = ""
doc, _, body = fixture.partition('"""')
cases = []
for case in body.split("$")[1:]:
argv, _, expect = case.strip().partition("\n")
expect = json.loads(expect)
prog, _, argv = argv.strip().partition(" ")
cases.append((prog, argv, expect))

yield name, doc, cases
yield doc, cases


class DocoptTestFile(pytest.File):
def collect(self):
raw = self.fspath.open().read()
index = 1

for name, doc, cases in parse_test(raw):
name = "%s(%d)" % (self.fspath.purebasename, index)
raw = self.path.open().read()
for i, (doc, cases) in enumerate(parse_test(raw), 1):
name = f"{self.path.stem}({i})"
for case in cases:
yield DocoptTestItem.from_parent(
name=name, parent=self, doc=doc, case=case
)
index += 1


class DocoptTestItem(pytest.Item):
Expand All @@ -67,14 +60,14 @@ def repr_failure(self, excinfo):
(
"usecase execution failed:",
self.doc.rstrip(),
"$ %s %s" % (self.prog, self.argv),
"result> %s" % json.dumps(excinfo.value.args[1]),
"expect> %s" % json.dumps(self.expect),
f"$ {self.prog} {self.argv}",
f"result> {json.dumps(excinfo.value.args[1])}",
f"expect> {json.dumps(self.expect)}",
)
)

def reportinfo(self):
return self.fspath, 0, "usecase: %s" % self.name
return self.path, 0, f"usecase: {self.name}"


class DocoptTestException(Exception):
Expand Down
2 changes: 0 additions & 2 deletions tests/requirements.txt

This file was deleted.

21 changes: 0 additions & 21 deletions tox.ini

This file was deleted.