A minimum test set

This commit is contained in:
Julien Palard 2019-12-10 10:09:21 +01:00 committed by GitHub
parent 3897a7fb0b
commit fde428ead7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 240 additions and 29 deletions

60
.gitignore vendored
View File

@ -1,3 +1,8 @@
# Created by https://www.gitignore.io/api/python
# Edit at https://www.gitignore.io/?templates=python
### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
@ -8,7 +13,6 @@ __pycache__/
# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
@ -20,9 +24,13 @@ lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
@ -37,20 +45,22 @@ pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
*.cover
.hypothesis/
.pytest_cache/
# Translations
*.mo
*.pot
# Django stuff:
*.log
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
@ -58,7 +68,45 @@ docs/_build/
# PyBuilder
target/
# pyenv python configuration file
# pyenv
.python-version
venv/
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# celery beat schedule file
celerybeat-schedule
# SageMath parsed files
*.sage.py
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# Mr Developer
.mr.developer.cfg
.project
.pydevproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
# End of https://www.gitignore.io/api/python
/venv

14
.travis.yml Normal file
View File

@ -0,0 +1,14 @@
language: python
matrix:
include:
- python: "3.6"
env: TOX_ENV=py36
- python: "3.7"
env: TOX_ENV=py37
- python: "3.8"
env: TOX_ENV=py38,black,flake8,pylint,mypy
install:
- pip uninstall -y virtualenv
- pip install tox
script:
- tox -e $TOX_ENV

View File

@ -1,10 +1,13 @@
========
powrap
========
======
|build| |pypi|
.. image:: https://img.shields.io/pypi/v/powrap.svg
:target: https://pypi.python.org/pypi/powrap
.. |build| image:: https://travis-ci.org/JulienPalard/powrap.svg?branch=master
:target: https://travis-ci.org/JulienPalard/powrap
.. |pypi| image:: https://img.shields.io/pypi/v/powrap.svg
:target: https://pypi.python.org/pypi/powrap
Script to fix indentation of given ``.po`` files. If ``--modified`` is
given, it will only fix modified files according to git (usefull if
@ -16,4 +19,9 @@ This package only runs ``msgcat`` from the ``gettext`` package, so if
your distribution don't have it, it just won't work.
* Free software: MIT license
Contributing
============
Start by creating a venv and installing `requirements-dev.in`.
To run the tests, use `tox -p auto`.

View File

@ -1,3 +1,8 @@
"""Script to fix indentation of given ``.po`` files. If ``--modified`` is
given, it will only fix modified files according to git (usefull if
your ``.po`` files are versionned).
"""
__author__ = """Julien Palard"""
__email__ = "julien@palard.fr"
__version__ = "0.3.1"

View File

@ -1 +1,4 @@
"""python -m powrap entry point.
"""
__import__("powrap.powrap").powrap.main()

View File

@ -3,8 +3,9 @@
"""Fix style of uncommited po files, or all if --all is given.
"""
import argparse
import sys
from shlex import quote
from typing import Iterable
from pathlib import Path
from subprocess import check_output, run
from tempfile import NamedTemporaryFile
@ -14,7 +15,7 @@ from tqdm import tqdm
from powrap import __version__
def check_style(po_files, no_wrap=False, quiet=False):
def check_style(po_files: Iterable[str], no_wrap=False, quiet=False):
"""Check style of given po_files
"""
to_fix = []
@ -51,7 +52,8 @@ def fix_style(po_files, no_wrap=False, quiet=False):
def parse_args():
import argparse
"""Parse powrap command line arguments.
"""
def path(path_str):
path_obj = Path(path_str)
@ -99,11 +101,13 @@ def parse_args():
args = parser.parse_args()
if not args.po_files and not args.modified:
parser.print_help()
exit(1)
sys.exit(1)
return args
def main():
"""Powrap main entrypoint (parsing command line and all).
"""
args = parse_args()
if args.modified:
git_status = check_output(["git", "status", "--porcelain"], encoding="utf-8")

View File

@ -1,5 +1,9 @@
setuptools
wheel
twine
black
pip-tools
black
flake8
mypy
pip-tools
pylint
pytest
tox
twine

View File

@ -5,7 +5,8 @@
# pip-compile requirements-dev.in
#
appdirs==1.4.3 # via black
attrs==19.3.0 # via black
astroid==2.3.3 # via pylint
attrs==19.3.0 # via black, pytest
black==19.10b0
bleach==3.1.0 # via readme-renderer
certifi==2019.9.11 # via requests
@ -14,28 +15,48 @@ chardet==3.0.4 # via requests
click==7.0 # via black, pip-tools
cryptography==2.8 # via secretstorage
docutils==0.15.2 # via readme-renderer
entrypoints==0.3 # via keyring
entrypoints==0.3 # via flake8, keyring
filelock==3.0.12 # via tox
flake8==3.7.9
idna==2.8 # via requests
isort==4.3.21 # via pylint
jeepney==0.4.1 # via secretstorage
keyring==19.2.0 # via twine
lazy-object-proxy==1.4.3 # via astroid
mccabe==0.6.1 # via flake8, pylint
more-itertools==8.0.2 # via pytest
mypy-extensions==0.4.3 # via mypy
mypy==0.750
packaging==19.2 # via pytest, tox
pathspec==0.6.0 # via black
pip-tools==4.3.0
pkginfo==1.5.0.1 # via twine
pluggy==0.13.1 # via pytest, tox
py==1.8.0 # via pytest, tox
pycodestyle==2.5.0 # via flake8
pycparser==2.19 # via cffi
pyflakes==2.1.1 # via flake8
pygments==2.4.2 # via readme-renderer
pylint==2.4.4
pyparsing==2.4.5 # via packaging
pytest==5.3.1
readme-renderer==24.0 # via twine
regex==2019.11.1 # via black
requests-toolbelt==0.9.1 # via twine
requests==2.22.0 # via requests-toolbelt, twine
secretstorage==3.1.1 # via keyring
six==1.13.0 # via bleach, cryptography, pip-tools, readme-renderer
toml==0.10.0 # via black
six==1.13.0 # via astroid, bleach, cryptography, packaging, pip-tools, readme-renderer, tox
toml==0.10.0 # via black, tox
tox==3.14.2
tqdm==4.39.0 # via twine
twine==3.1.0
typed-ast==1.4.0 # via black
typed-ast==1.4.0 # via black, mypy
typing-extensions==3.7.4.1 # via mypy
urllib3==1.25.7 # via requests
virtualenv==16.7.8 # via tox
wcwidth==0.1.7 # via pytest
webencodings==0.5.1 # via bleach
wheel==0.33.6
wrapt==1.11.2 # via astroid
# The following packages are considered to be unsafe in a requirements file:
# setuptools

View File

@ -1,4 +0,0 @@
pip==8.1.2
wheel==0.29.0
flake8==2.6.0
twine

30
tests/bad/glossary.po Normal file
View File

@ -0,0 +1,30 @@
# Copyright (C) 2001-2018, Python Software Foundation
# For licence information, see README file.
#
msgid ""
msgstr ""
"Project-Id-Version: Python 3\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-10-09 17:54+0200\n"
"PO-Revision-Date: 2019-12-10 09:26+0100\n"
"Last-Translator: Grenoya <grenoya@zarb.org>\n"
"Language-Team: FRENCH <traductions@lists.afpy.org>\n"
"Language: fr\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 2.2.1\n"
#: ../Doc/glossary.rst:5
msgid "Glossary"
msgstr "Glossaire"
#: ../Doc/glossary.rst:10
msgid "``>>>``"
msgstr "``>>>``"
#: ../Doc/glossary.rst:12
msgid ""
"The default Python prompt of the interactive shell. Often seen for code "
"examples which can be executed interactively in the interpreter."
msgstr "L'invite de commande utilisée par défaut dans l'interpréteur interactif. On la voit souvent dans des exemples de code qui peuvent être exécutés interactivement dans l'interpréteur."

33
tests/good/glossary.po Normal file
View File

@ -0,0 +1,33 @@
# Copyright (C) 2001-2018, Python Software Foundation
# For licence information, see README file.
#
msgid ""
msgstr ""
"Project-Id-Version: Python 3\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-10-09 17:54+0200\n"
"PO-Revision-Date: 2019-12-10 09:26+0100\n"
"Last-Translator: Grenoya <grenoya@zarb.org>\n"
"Language-Team: FRENCH <traductions@lists.afpy.org>\n"
"Language: fr\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 2.2.1\n"
#: ../Doc/glossary.rst:5
msgid "Glossary"
msgstr "Glossaire"
#: ../Doc/glossary.rst:10
msgid "``>>>``"
msgstr "``>>>``"
#: ../Doc/glossary.rst:12
msgid ""
"The default Python prompt of the interactive shell. Often seen for code "
"examples which can be executed interactively in the interpreter."
msgstr ""
"L'invite de commande utilisée par défaut dans l'interpréteur interactif. On "
"la voit souvent dans des exemples de code qui peuvent être exécutés "
"interactivement dans l'interpréteur."

17
tests/test_powrap.py Normal file
View File

@ -0,0 +1,17 @@
from pathlib import Path
import pytest
from powrap import powrap
FIXTURE_DIR = Path(__file__).resolve().parent
@pytest.mark.parametrize("po_file", (FIXTURE_DIR / "bad").glob("*.po"))
def test_fail_on_bad_wrapping(po_file):
assert powrap.check_style([po_file]) == [po_file]
@pytest.mark.parametrize("po_file", (FIXTURE_DIR / "good").glob("*.po"))
def test_succees_on_good_wrapping(po_file):
assert powrap.check_style([po_file]) == []

28
tox.ini Normal file
View File

@ -0,0 +1,28 @@
[flake8]
;Because black
ignore = E203
max-line-length = 88
[tox]
envlist = py36, py37, py38, flake8, mypy, black
isolated_build = False
skip_missing_interpreters = True
[testenv]
deps = -r requirements-dev.txt
commands = pytest
[testenv:flake8]
deps = flake8
commands = flake8 tests/ powrap/
[testenv:pylint]
commands = pylint powrap/
[testenv:black]
deps = black
commands = black --check --diff tests/ powrap/
[testenv:mypy]
deps = mypy
commands = mypy --ignore-missing-imports powrap/