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

Ensure test quality via linting #19

Merged
merged 1 commit into from
Nov 6, 2023
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
1 change: 1 addition & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ disable=
redefined-builtin,
too-few-public-methods,
too-many-branches,
unspecified-encoding,
useless-option-value, # disables warning in recent pylint that does not check for no-self-use anymore

[REPORTS]
Expand Down
183 changes: 97 additions & 86 deletions tests/test_build_antlr.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
# This file may not be copied, modified, or distributed except
# according to those terms.

import pytest
import sys

from distutils.errors import DistutilsModuleError
from os import makedirs
from os.path import abspath, dirname, isfile, join
from distutils.errors import DistutilsModuleError

import pytest

from setuptools.dist import Distribution

import antlerinator
Expand Down Expand Up @@ -38,19 +40,19 @@ def test_build_antlr_providers(tmpdir):
with tmpdir.as_cwd():
antlr_jar_path = antlerinator.download(version=tested_antlr_version, path=join(str(tmpdir), 'antlr.jar'))

dist = Distribution(dict(
name='pkg',
script_name='setup.py',
script_args=['build_antlr'],
options=dict(
build_antlr=dict(
commands=f'''
dist = Distribution({
'name': 'pkg',
'script_name': 'setup.py',
'script_args': ['build_antlr'],
'options': {
'build_antlr': {
'commands': f'''
antlerinator:{tested_antlr_version} {join(resources_dir, "Hello.g4")} -Dlanguage=Python3 -o {tmpdir} -Xexact-output-dir
file:{antlr_jar_path} {join(resources_dir, "Bello.g4")} -Dlanguage=Python3 -o {tmpdir} -Xexact-output-dir
''',
),
),
))
},
},
})

dist.parse_command_line()
dist.run_commands()
Expand All @@ -66,17 +68,17 @@ def test_build_antlr_java(tmpdir):
Test whether ``build_antlr`` can deal with a custom java VM.
"""
with tmpdir.as_cwd():
dist = Distribution(dict(
name='pkg',
script_name='setup.py',
script_args=['build_antlr'],
options=dict(
build_antlr=dict(
commands='file:antlr.jar Dummy.g4',
java=f'{join(resources_dir, "mock_java")}{script_ext}',
),
),
))
dist = Distribution({
'name': 'pkg',
'script_name': 'setup.py',
'script_args': ['build_antlr'],
'options': {
'build_antlr': {
'commands': 'file:antlr.jar Dummy.g4',
'java': f'{join(resources_dir, "mock_java")}{script_ext}',
},
},
})

dist.parse_command_line()
dist.run_commands()
Expand All @@ -92,19 +94,20 @@ def test_build(tmpdir):
command is invoked (which is also invoked during ``install``).
"""
with tmpdir.as_cwd():
dist = Distribution(dict(
name='pkg',
packages=['pkg'],
script_name='setup.py',
script_args=['build', f'--build-lib={join("build", "lib")}'], # NOTE: --build-lib is necessary to ensure that purelib build directory is used
options=dict(
build_antlr=dict(
commands=f'antlerinator:{tested_antlr_version} {join(resources_dir, "Hello.g4")} -Dlanguage=Python3 -o {join(str(tmpdir), "pkg")} -Xexact-output-dir',
),
),
))
dist = Distribution({
'name': 'pkg',
'packages': ['pkg'],
'script_name': 'setup.py',
'script_args': ['build', f'--build-lib={join("build", "lib")}'], # NOTE: --build-lib is necessary to ensure that purelib build directory is used
'options': {
'build_antlr': {
'commands': f'antlerinator:{tested_antlr_version} {join(resources_dir, "Hello.g4")} -Dlanguage=Python3 -o {join(str(tmpdir), "pkg")} -Xexact-output-dir',
},
},
})
makedirs('pkg')
open(join('pkg', '__init__.py'), 'w').close()
with open(join('pkg', '__init__.py'), 'w'):
pass

dist.parse_command_line()
dist.run_commands()
Expand All @@ -119,19 +122,20 @@ def test_develop(tmpdir):
development mode).
"""
with tmpdir.as_cwd():
dist = Distribution(dict(
name='pkg',
packages=['pkg'],
script_name='setup.py',
script_args=['develop'],
options=dict(
build_antlr=dict(
commands=f'antlerinator:{tested_antlr_version} {join(resources_dir, "Hello.g4")} -Dlanguage=Python3 -o {join(str(tmpdir), "pkg")} -Xexact-output-dir',
),
),
))
dist = Distribution({
'name': 'pkg',
'packages': ['pkg'],
'script_name': 'setup.py',
'script_args': ['develop'],
'options': {
'build_antlr': {
'commands': f'antlerinator:{tested_antlr_version} {join(resources_dir, "Hello.g4")} -Dlanguage=Python3 -o {join(str(tmpdir), "pkg")} -Xexact-output-dir',
},
},
})
makedirs('pkg')
open(join('pkg', '__init__.py'), 'w').close()
with open(join('pkg', '__init__.py'), 'w'):
pass

dist.parse_command_line()
dist.run_commands()
Expand All @@ -147,19 +151,20 @@ def test_editable_wheel(tmpdir):
editable wheels).
"""
with tmpdir.as_cwd():
dist = Distribution(dict(
name='pkg',
packages=['pkg'],
script_name='setup.py',
script_args=['editable_wheel'],
options=dict(
build_antlr=dict(
commands=f'antlerinator:{tested_antlr_version} {join(resources_dir, "Hello.g4")} -Dlanguage=Python3 -o {join(str(tmpdir), "pkg")} -Xexact-output-dir',
),
),
))
dist = Distribution({
'name': 'pkg',
'packages': ['pkg'],
'script_name': 'setup.py',
'script_args': ['editable_wheel'],
'options': {
'build_antlr': {
'commands': f'antlerinator:{tested_antlr_version} {join(resources_dir, "Hello.g4")} -Dlanguage=Python3 -o {join(str(tmpdir), "pkg")} -Xexact-output-dir',
},
},
})
makedirs('pkg')
open(join('pkg', '__init__.py'), 'w').close()
with open(join('pkg', '__init__.py'), 'w'):
pass

dist.parse_command_line()
dist.run_commands()
Expand All @@ -173,21 +178,24 @@ def test_clean(tmpdir):
Test whether cleanup removes generated files.
"""
with tmpdir.as_cwd():
dist = Distribution(dict(
name='pkg',
packages=['pkg'],
script_name='setup.py',
script_args=['clean'],
options=dict(
build_antlr=dict(
output=join('pkg', 'Dummy*.py'),
),
),
))
dist = Distribution({
'name': 'pkg',
'packages': ['pkg'],
'script_name': 'setup.py',
'script_args': ['clean'],
'options': {
'build_antlr': {
'output': join('pkg', 'Dummy*.py'),
},
},
})
makedirs('pkg')
open(join('pkg', '__init__.py'), 'w').close()
open(join('pkg', 'DummyLexer.py'), 'w').close()
open(join('pkg', 'DummyParser.py'), 'w').close()
with open(join('pkg', '__init__.py'), 'w'):
pass
with open(join('pkg', 'DummyLexer.py'), 'w'):
pass
with open(join('pkg', 'DummyParser.py'), 'w'):
pass

dist.parse_command_line()
dist.run_commands()
Expand All @@ -203,20 +211,23 @@ def test_sdist(tmpdir):
MANIFEST.in.
"""
with tmpdir.as_cwd():
dist = Distribution(dict(
name='pkg',
packages=['pkg'],
script_name='setup.py',
options=dict(
build_antlr=dict(
output=join('pkg', 'Dummy*.py'),
),
),
))
dist = Distribution({
'name': 'pkg',
'packages': ['pkg'],
'script_name': 'setup.py',
'options': {
'build_antlr': {
'output': join('pkg', 'Dummy*.py'),
},
},
})
makedirs('pkg')
open(join('pkg', '__init__.py'), 'w').close()
open(join('pkg', 'DummyLexer.py'), 'w').close()
open(join('pkg', 'DummyParser.py'), 'w').close()
with open(join('pkg', '__init__.py'), 'w'):
pass
with open(join('pkg', 'DummyLexer.py'), 'w'):
pass
with open(join('pkg', 'DummyParser.py'), 'w'):
pass
with open('MANIFEST.in', 'w') as f:
f.write('exclude pkg/Dummy*.py')

Expand Down
7 changes: 4 additions & 3 deletions tests/test_download.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# Copyright (c) 2017-2022 Renata Hodovan, Akos Kiss.
# Copyright (c) 2017-2023 Renata Hodovan, Akos Kiss.
#
# Licensed under the BSD 3-Clause License
# <LICENSE.rst or https://opensource.org/licenses/BSD-3-Clause>.
# This file may not be copied, modified, or distributed except
# according to those terms.

import os
import pytest
import subprocess
import sys

import pytest

import antlerinator


Expand Down Expand Up @@ -43,7 +44,7 @@ def run_download(args, exp_ok):
True,
False
])
class TestDownload(object):
class TestDownload:

def test_cli(self, antlr_version, default_path, tmpdir):
args = [f'--antlr-version={antlr_version}']
Expand Down
5 changes: 3 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ usedevelop = true
deps =
pycodestyle
pylint
pytest
commands =
pylint src/antlerinator
pycodestyle src/antlerinator --ignore=E501
pylint src/antlerinator tests
pycodestyle src/antlerinator tests --ignore=E501

[testenv:docs]
deps =
Expand Down