Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/melexis/xunit2rst into do…
Browse files Browse the repository at this point in the history
…cument-color-test-results
  • Loading branch information
JasperCraeghs committed Jan 12, 2024
2 parents a0226df + b41dcc9 commit 215ef79
Show file tree
Hide file tree
Showing 15 changed files with 71 additions and 65 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
pip install twine build
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python setup.py sdist bdist_wheel
python -m build
twine upload dist/*
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ wheels/
.installed.cfg
*.egg
MANIFEST
mlx/__xunit2rst_version__.py
mlx/xunit2rst/__version__.py

# PyInstaller
# Usually these files are written by a python script from a template
Expand Down
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ include tox.ini
recursive-include mlx *.mako
recursive-include mlx *.css

exclude mlx/__xunit2rst_version__.py
exclude mlx/xunit2rst/__version__.py
exclude .pylintrc
exclude doc/source/generated/*

Expand Down
1 change: 0 additions & 1 deletion mlx/__init__.py

This file was deleted.

Empty file added mlx/xunit2rst/__init__.py
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["setuptools-scm>=6.0.0", "setuptools>=69.0.3"]
build-backend = "setuptools.build_meta"
18 changes: 10 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from setuptools import setup, find_packages
from setuptools import find_namespace_packages, setup

requires = [
'mako',
Expand All @@ -8,9 +8,8 @@
setup(
name='mlx.xunit2rst',
use_scm_version={
'write_to': 'mlx/__xunit2rst_version__.py'
'write_to': 'mlx/xunit2rst/__version__.py'
},
setup_requires=['setuptools-scm>=6.0.0'],
url='https://github.com/melexis/xunit2rst',
license='Apache License Version 2.0',
author='JasperCraeghs',
Expand All @@ -37,17 +36,20 @@
'Topic :: Utilities',
],
platforms='any',
packages=find_packages(exclude=['tests', 'doc']),
package_data={'mlx.xunit2rst': ['mlx/*.mako', 'mlx/assets/*']},
packages=find_namespace_packages(where='.'),
package_dir={"": "."},
package_data={
'mlx.xunit2rst': ['*.mako'],
'mlx.xunit2rst.assets': ['*.css']
},
include_package_data=True,
install_requires=requires,
python_requires='>=3.8',
namespace_packages=['mlx'],
keywords=['xUnit', 'JUnit', 'XML', 'reStructuredText', 'sphinx', 'rst', 'testing', 'traceability', 'documentation'],
entry_points={
'console_scripts': [
'mlx.xunit2rst = mlx.xunit2rst:main',
'xunit2rst = mlx.xunit2rst:main',
'mlx.xunit2rst = mlx.xunit2rst.xunit2rst:main',
'xunit2rst = mlx.xunit2rst.xunit2rst:main',
]
},
)
6 changes: 3 additions & 3 deletions tests/acceptance_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import unittest
from pathlib import Path

from mlx.xunit2rst import create_parser, generate_xunit_to_rst
from mlx.xunit2rst import xunit2rst as dut

TOP_DIR = Path(__file__).parents[1]
TEST_OUT_DIR = Path(__file__).parent / 'test_out'
Expand All @@ -18,7 +18,7 @@
def xunit2rst_check(input_xml, output_rst, itemize_suites=False, prefix='', trim=False, type_=None, failures=False,
log_file='', add_links=False):
''' Helper function for testing whether mlx.xunit2rst produces the expected output '''
arg_parser = create_parser()
arg_parser = dut.create_parser()
command = ['-i', input_xml, '-o', output_rst]
if itemize_suites:
command.append('--itemize-suites')
Expand All @@ -37,7 +37,7 @@ def xunit2rst_check(input_xml, output_rst, itemize_suites=False, prefix='', trim
print(command)
args = arg_parser.parse_args(command)

generate_xunit_to_rst(
dut.generate_xunit_to_rst(
args.input_file,
args.rst_output_file,
args.itemize_suites,
Expand Down
6 changes: 3 additions & 3 deletions tests/mako_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from pathlib import Path
from unittest import TestCase

from mlx.xunit2rst import ITEST, render_template
from mlx.xunit2rst import xunit2rst as dut

TEST_OUT_DIR = Path(__file__).parent / 'test_out'

Expand All @@ -16,13 +16,13 @@ def test_mako_error_handling(self):
variable '''
kwargs = {
'report_name': 'my_report',
'info': ITEST,
'info': dut.ITEST,
'prefix': 'MAKO_TEST-',
}
test_case = TestCase()
with test_case.assertLogs() as log_cm:
with self.assertRaises(TypeError):
render_template((TEST_OUT_DIR / 'never_created_file.rst'), **kwargs)
dut.render_template((TEST_OUT_DIR / 'never_created_file.rst'), **kwargs)
test_case.assertIn('Exception raised in Mako template, which will be re-raised after logging line info:',
log_cm.output[0])
test_case.assertIn('File ', log_cm.output[-1])
Expand Down
88 changes: 44 additions & 44 deletions tests/prefix_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,45 @@
import unittest
from pathlib import Path

from mlx.xunit2rst import build_prefix_and_set, parse_xunit_root, verify_prefix_set, ITEST, UTEST, QTEST
from mlx.xunit2rst import xunit2rst as dut

TEST_IN_DIR = Path(__file__).parent / 'test_in'


class TestPrefix(unittest.TestCase):
def test_build_prefix_and_set_utest_default(self):
''' Use default prefix for unit test reports '''
test_suites, initial_prefix_set, _ = parse_xunit_root(TEST_IN_DIR / 'utest_my_lib_no_prefix_report.xml')
self.assertEqual(initial_prefix_set, UTEST)
test_suites, initial_prefix_set, _ = dut.parse_xunit_root(TEST_IN_DIR / 'utest_my_lib_no_prefix_report.xml')
self.assertEqual(initial_prefix_set, dut.UTEST)

prefix_set, prefix = build_prefix_and_set(test_suites, initial_prefix_set, '', True, None)
prefix_set, prefix = dut.build_prefix_and_set(test_suites, initial_prefix_set, '', True, None)
self.assertEqual(prefix_set, initial_prefix_set)
self.assertEqual(prefix, 'UTEST-')

def test_build_prefix_and_set_itest_default(self):
''' Use default prefix for integration test reports '''
test_suites, initial_prefix_set, _ = parse_xunit_root(TEST_IN_DIR / 'itest_report.xml')
self.assertEqual(initial_prefix_set, ITEST)
test_suites, initial_prefix_set, _ = dut.parse_xunit_root(TEST_IN_DIR / 'itest_report.xml')
self.assertEqual(initial_prefix_set, dut.ITEST)

prefix_set, prefix = build_prefix_and_set(test_suites, initial_prefix_set, '', True, None)
prefix_set, prefix = dut.build_prefix_and_set(test_suites, initial_prefix_set, '', True, None)
self.assertEqual(prefix_set, initial_prefix_set)
self.assertEqual(prefix, 'ITEST-')

def test_build_prefix_and_set_from_name(self):
''' Get prefix from element name '''
test_suites, initial_prefix_set, _ = parse_xunit_root(TEST_IN_DIR / 'utest_my_lib_report.xml')
self.assertEqual(initial_prefix_set, UTEST)
test_suites, initial_prefix_set, _ = dut.parse_xunit_root(TEST_IN_DIR / 'utest_my_lib_report.xml')
self.assertEqual(initial_prefix_set, dut.UTEST)

prefix_set, prefix = build_prefix_and_set(test_suites, initial_prefix_set, '', True, None)
prefix_set, prefix = dut.build_prefix_and_set(test_suites, initial_prefix_set, '', True, None)
self.assertEqual(prefix_set, initial_prefix_set)
self.assertEqual(prefix, 'UTEST_MY_LIB-')

def test_build_prefix_and_set_from_arg(self):
''' Get prefix from input argument `--prefix` and trim suffix of prefix '''
test_suites, initial_prefix_set, _ = parse_xunit_root(TEST_IN_DIR / 'utest_my_lib_report.xml')
self.assertEqual(initial_prefix_set, UTEST)
test_suites, initial_prefix_set, _ = dut.parse_xunit_root(TEST_IN_DIR / 'utest_my_lib_report.xml')
self.assertEqual(initial_prefix_set, dut.UTEST)

prefix_set, prefix = build_prefix_and_set(test_suites, initial_prefix_set, 'TEST_MY_LIB_-', True, None)
prefix_set, prefix = dut.build_prefix_and_set(test_suites, initial_prefix_set, 'TEST_MY_LIB_-', True, None)
self.assertEqual(prefix_set, initial_prefix_set)
self.assertEqual(prefix, 'TEST_MY_LIB-')

Expand All @@ -50,32 +50,32 @@ def test_build_prefix_and_set_from_arg_swap_set(self):
Get prefix from input argument `--prefix` and base prefix_set on its first letter.
Don't trim suffix of prefix.
'''
test_suites, initial_prefix_set, _ = parse_xunit_root(TEST_IN_DIR / 'itest_report.xml')
self.assertEqual(initial_prefix_set, ITEST)
test_suites, initial_prefix_set, _ = dut.parse_xunit_root(TEST_IN_DIR / 'itest_report.xml')
self.assertEqual(initial_prefix_set, dut.ITEST)

prefix_set, prefix = build_prefix_and_set(test_suites, initial_prefix_set, 'UTEST_MY_LIB_-', False, None)
prefix_set, prefix = dut.build_prefix_and_set(test_suites, initial_prefix_set, 'UTEST_MY_LIB_-', False, None)
self.assertNotEqual(prefix_set, initial_prefix_set)
self.assertEqual(prefix_set, UTEST)
self.assertEqual(prefix_set, dut.UTEST)
self.assertEqual(prefix, 'UTEST_MY_LIB_-')

def test_build_prefix_and_set_priority(self):
''' Argument --type must have the highest priority for determining the correct prefix_set. '''
test_suites, initial_prefix_set, _ = parse_xunit_root(TEST_IN_DIR / 'utest_my_lib_report.xml')
self.assertEqual(initial_prefix_set, UTEST)
test_suites, initial_prefix_set, _ = dut.parse_xunit_root(TEST_IN_DIR / 'utest_my_lib_report.xml')
self.assertEqual(initial_prefix_set, dut.UTEST)

prefix_set, prefix = build_prefix_and_set(test_suites, initial_prefix_set, 'UTEST_HOWDY-', False, 'i')
prefix_set, prefix = dut.build_prefix_and_set(test_suites, initial_prefix_set, 'UTEST_HOWDY-', False, 'i')
self.assertNotEqual(prefix_set, initial_prefix_set)
self.assertEqual(prefix_set, ITEST)
self.assertEqual(prefix_set, dut.ITEST)
self.assertEqual(prefix, 'UTEST_HOWDY-')

def test_content_files(self):
''' Test the extraction of the content file path '''
_, _, content_files = parse_xunit_root(TEST_IN_DIR / 'qtest_my_lib_report.xml')
_, _, content_files = dut.parse_xunit_root(TEST_IN_DIR / 'qtest_my_lib_report.xml')
self.assertEqual(content_files, {3: Path("../../doc/source/extra_content.yml")})

def test_content_files_no_root(self):
''' Test the extraction of the content file path when the XML has no valid root element '''
_, _, content_files = parse_xunit_root(TEST_IN_DIR / 'itest_report.xml')
_, _, content_files = dut.parse_xunit_root(TEST_IN_DIR / 'itest_report.xml')
self.assertEqual(content_files, {0: Path('./extra_content1.yml')})

def test_verify_prefix_set(self):
Expand All @@ -84,31 +84,31 @@ def test_verify_prefix_set(self):
start with u/i/q (case-insensitive). The prefix argument has the second highest priority. A last resort is to
keep the input prefix_set.
'''
self.assertEqual(verify_prefix_set(UTEST, 'UTEST-', 'Itest'), ITEST)
self.assertEqual(verify_prefix_set(UTEST, 'UTEST-', 'i'), ITEST)
self.assertEqual(verify_prefix_set(UTEST, '', 'i'), ITEST)
self.assertEqual(verify_prefix_set(ITEST, 'ITEST-', 'Utest'), UTEST)
self.assertEqual(verify_prefix_set(UTEST, 'ITEST-', 'u'), UTEST)
self.assertEqual(verify_prefix_set(UTEST, 'UTEST-', 'u'), UTEST)
self.assertEqual(verify_prefix_set(UTEST, 'BLAH-', None), UTEST)
self.assertEqual(verify_prefix_set(ITEST, 'BLAH-', None), ITEST)
self.assertEqual(verify_prefix_set(UTEST, 'ITEST-', None), ITEST)
self.assertEqual(verify_prefix_set(ITEST, 'UTEST-', None), UTEST)
self.assertEqual(verify_prefix_set(ITEST, 'QTEST-', None), QTEST)
self.assertEqual(verify_prefix_set(ITEST, 'ITEST-', 'q'), QTEST)
self.assertEqual(verify_prefix_set(UTEST, 'UTEST-', 'Qtest'), QTEST)
self.assertEqual(verify_prefix_set(QTEST, '', 'u'), UTEST)
self.assertEqual(verify_prefix_set(QTEST, '', 'i'), ITEST)
self.assertEqual(verify_prefix_set(QTEST, 'UTEST', 'i'), ITEST)
self.assertEqual(verify_prefix_set(QTEST, 'FOO-', None), QTEST)
self.assertEqual(dut.verify_prefix_set(dut.UTEST, 'UTEST-', 'Itest'), dut.ITEST)
self.assertEqual(dut.verify_prefix_set(dut.UTEST, 'UTEST-', 'i'), dut.ITEST)
self.assertEqual(dut.verify_prefix_set(dut.UTEST, '', 'i'), dut.ITEST)
self.assertEqual(dut.verify_prefix_set(dut.ITEST, 'ITEST-', 'Utest'), dut.UTEST)
self.assertEqual(dut.verify_prefix_set(dut.UTEST, 'ITEST-', 'u'), dut.UTEST)
self.assertEqual(dut.verify_prefix_set(dut.UTEST, 'UTEST-', 'u'), dut.UTEST)
self.assertEqual(dut.verify_prefix_set(dut.UTEST, 'BLAH-', None), dut.UTEST)
self.assertEqual(dut.verify_prefix_set(dut.ITEST, 'BLAH-', None), dut.ITEST)
self.assertEqual(dut.verify_prefix_set(dut.UTEST, 'ITEST-', None), dut.ITEST)
self.assertEqual(dut.verify_prefix_set(dut.ITEST, 'UTEST-', None), dut.UTEST)
self.assertEqual(dut.verify_prefix_set(dut.ITEST, 'QTEST-', None), dut.QTEST)
self.assertEqual(dut.verify_prefix_set(dut.ITEST, 'ITEST-', 'q'), dut.QTEST)
self.assertEqual(dut.verify_prefix_set(dut.UTEST, 'UTEST-', 'Qtest'), dut.QTEST)
self.assertEqual(dut.verify_prefix_set(dut.QTEST, '', 'u'), dut.UTEST)
self.assertEqual(dut.verify_prefix_set(dut.QTEST, '', 'i'), dut.ITEST)
self.assertEqual(dut.verify_prefix_set(dut.QTEST, 'UTEST', 'i'), dut.ITEST)
self.assertEqual(dut.verify_prefix_set(dut.QTEST, 'FOO-', None), dut.QTEST)
with self.assertRaises(ValueError):
verify_prefix_set(UTEST, 'UTEST-', 't')
dut.verify_prefix_set(dut.UTEST, 'UTEST-', 't')
with self.assertRaises(ValueError):
verify_prefix_set(ITEST, 'ITEST', 't')
dut.verify_prefix_set(dut.ITEST, 'ITEST', 't')
with self.assertRaises(ValueError):
verify_prefix_set(ITEST, '', '')
dut.verify_prefix_set(dut.ITEST, '', '')
with self.assertRaises(ValueError):
verify_prefix_set(QTEST, '', 't')
dut.verify_prefix_set(dut.QTEST, '', 't')


if __name__ == '__main__':
Expand Down
6 changes: 4 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,21 @@ usedevelop = false
deps =
pytest-cov
commands=
xunit2rst --help
{posargs:py.test --cov=mlx --cov-report=term-missing -vv tests/}

[testenv:check]
deps =
{[testenv]deps}
docutils
build
twine >= 1.12.0
check-manifest
readme-renderer
flake8
skip_install = true
commands =
python setup.py sdist
python -m build
twine check dist/*
check-manifest {toxinidir}
flake8 mlx tests setup.py
Expand All @@ -50,7 +52,7 @@ deps=
{[testenv]deps}
sphinx_rtd_theme
mlx.traceability >= 4.3.2
mlx.warnings >= 1.2.0
mlx.warnings >= 5.0.0
mlx.robot2rst >= 3.3.0, <4
robotframework >= 5.0.1
sphinx_selective_exclude >= 1.0.3
Expand Down

0 comments on commit 215ef79

Please sign in to comment.