Wykres commitów

47 Commity (98f8a7e77181d9558c0080e6a6c9cf920503e4a3)

Autor SHA1 Wiadomość Data
Andrew Leech f672353180 unittest-discover: Print results when no tests are found/run.
Prior to this commit, if no tests were found when running unittest discover
then nothing at all was written to stdout, leading one to think it's not
working at all.  CPython unittest does display a "0 tests run" sort of
output in such a case, and this commit ensures this package does the same.
2023-03-27 12:06:04 +11:00
Gavin Douch 23018a86bf unittest: Add subtest usage examples.
This work was funded by Planet Innovation.
2023-02-21 23:56:06 +11:00
Jim Mussared a08087249f top: Update Python formatting to black "2023 stable style".
See https://black.readthedocs.io/en/stable/the_black_code_style/index.html

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-02-03 17:12:38 +11:00
Andrzej Kowalczyk 863a018b89 unittest: Remove dependence on sys.exc_info.
This is not included by default in most builds, and isn't necessary for
this module anyway.

Also fix the local variable shadowing the traceback module in _capture_exc.

Added test for both (works on CPython and MicroPython).

Version bump to 0.10.2.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-01-31 12:38:00 +11:00
Jim Mussared 038b4ac657 unittest: Convert to a package.
This allows a much more natural way of implementing unitttest-discover:
 - unittest provides unittest/__init__.py
 - unittest-discover provides unittest/__main__.py

It also fixes an bug where unittest.py previously detected the presence of
unittest-discover.py by importing an checking for the ImportError. But that
could also be raised by a missing dependency. Now when you run
`micropython -m unittest` without unittest-discover, you get
`ImportError: no module named 'unittest.__main__'`, and without the
required deps, `ImportError: no module named 'argparse'`.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-11-09 14:56:34 +11:00
Oliver Joos 9bc0b15f11 unittest: Make AssertRaisesContext store exception for later retrieval.
The statement "with assertRaises(errtype) as ctxt" checks the type of a
raised exception, but did not store the exception into ctxt like unittest
of CPython.  The exception instance is usually used to check its message or
other args.
2022-10-04 12:28:43 +11:00
Jim Mussared 796a5986cd unittest: Move back to python-stdlib.
In order to make this more suitable for non-unix ports, the discovery
functionality is moved to a separate 'extension' module which can be
optionally installed.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-09-13 09:57:04 +10:00
Jim Mussared f3cfc52ab0 unix-ffi: Move more unix-only packages to unix-ffi.
With the dependencies captured in manifest.py, several packages in
python-stdlib were still unix-only due to direct or transitive dependencies
on unix-only or ffi modules.  Or they just make no sense to run on
microcontroller targets.

In a few cases (e.g. base64) where possible, the unix dependency could be
removed.

Updates manifest.py to use the `unix_ffi=True` arg to `require()` for these
libraries.

Rename re-pcre to re now that unix-ffi is effectively its own namespace.

Update unix-ffi/README.md, and strengthen the wording that the unix
libraries are unmaintained.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-09-05 17:50:42 +10:00
Jim Mussared ce66e701a5 all: Replace metadata.txt with manifest.py.
Uses the new require()/package()/module() functions from manifestfile.py.

Add manifest.py for iperf3 and pyjwt.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-09-05 17:50:28 +10:00
Jim Mussared ecef7a506c all: Remove all setup.py files.
These are unused and will be replaced with manifest.py.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-09-05 17:50:11 +10:00
Andrew Leech db4c739863 unittest: Version 0.9.0 2022-05-06 10:47:37 +10:00
Andrew Leech 959115d3a9 unittest: Add support for specifying custom TestRunner. 2022-05-06 10:47:37 +10:00
Steve Li 2d61dbdb93 unittest: Add setUpClass and tearDownClass handling.
Supports setUp and tearDown functionality at Class level.
2022-05-06 10:47:37 +10:00
Andrew Leech ddeb9a7da2 unittest: Improve failure text consistency with cpython. 2022-05-06 10:47:37 +10:00
Andrew Leech 9b6315a2ba unittest: Add exception capturing for subTest. 2022-05-06 10:47:37 +10:00
Andrew Leech 9f6f211506 unittest: Reset python env between tests. 2022-05-06 10:47:37 +10:00
Andrew Leech cb8d108ac1 unittest: Add test for environment isolation. 2022-05-06 10:47:37 +10:00
Andrew Leech a7b2f63117 unittest: Add discover function. 2022-05-06 10:47:37 +10:00
Andrew Leech 9d9ca3d59b unittest: Run test_* functions as well as TestCase classes. 2022-05-06 10:47:37 +10:00
Andrew Leech c7eb3de858 unittest: Print module name on result lines.
Matches cpython format.
2022-05-06 10:47:37 +10:00
Paul Sokolovsky f92833b015 unittest: Support TestCase subclasses with own runTest() method.
E.g. for doctest.

Signed-off-by: Paul Sokolovsky <pfalcon@users.sourceforge.net>
2022-05-06 10:47:37 +10:00
Paul Sokolovsky ac282d861e unittest: Add TextTestRunner as alias for TestRunner.
For CPython compatibility.

Signed-off-by: Paul Sokolovsky <pfalcon@users.sourceforge.net>
2022-05-06 10:47:37 +10:00
Paul Sokolovsky 5a53a75ec1 unittest: Print no. of skipped tests in a way compatible with CPython.
Perhaps, modern CPython (3.8).

Signed-off-by: Paul Sokolovsky <pfalcon@users.sourceforge.net>
2022-05-06 10:47:37 +10:00
Paul Sokolovsky 01fcd42042 unittest: test_unittest: Add tests for expectedFailure decorator.
Signed-off-by: Paul Sokolovsky <pfalcon@users.sourceforge.net>
2022-05-06 10:47:37 +10:00
Paul Sokolovsky 377ebbfe56 unittest: Add expectedFailure decorator.
Signed-off-by: Paul Sokolovsky <pfalcon@users.sourceforge.net>
2022-05-06 10:47:37 +10:00
Paul Sokolovsky 8e82f3d80b unittest: Support recursive TestSuite's.
Signed-off-by: Paul Sokolovsky <pfalcon@users.sourceforge.net>
2022-05-06 10:47:37 +10:00
Paul Sokolovsky e582666f5d unittest: Properly handle failures vs errors.
Also, rework result printing to be more compatible with CPython.

Signed-off-by: Paul Sokolovsky <pfalcon@users.sourceforge.net>
2022-05-06 10:47:37 +10:00
Paul Sokolovsky 1b46612f94 unittest: Implement basic addCleanup()/doCleanup().
Signed-off-by: Paul Sokolovsky <pfalcon@users.sourceforge.net>
2022-05-06 10:47:37 +10:00
Paul Sokolovsky 2c0b508e4d unittest: TestSuite: Add run() method.
For CPython compatibility.

Signed-off-by: Paul Sokolovsky <pfalcon@users.sourceforge.net>
2022-05-06 10:47:37 +10:00
Paul Sokolovsky 04dce89790 unittest: Add dummy TestCase.assertWarns() context manager.
Signed-off-by: Paul Sokolovsky <pfalcon@users.sourceforge.net>
2022-05-06 10:47:37 +10:00
Paul Sokolovsky 555f28ce6d unittest: Add dummy TestCase.subTest() context manager.
Just runs "subtests" in the scope of the main TestCase.

Signed-off-by: Paul Sokolovsky <pfalcon@users.sourceforge.net>
2022-05-06 10:47:37 +10:00
Paul Sokolovsky 7d77774027 unittest: Add TestCase.skipTest() method.
Signed-off-by: Paul Sokolovsky <pfalcon@users.sourceforge.net>
2022-05-06 10:47:37 +10:00
Paul Sokolovsky 5d3a44cb1c unittest: TestCase: Add (dummy) __init__.
Mostly to workaround inherited MicroPython's issues with inheritance.

Signed-off-by: Paul Sokolovsky <pfalcon@users.sourceforge.net>
2022-05-06 10:47:37 +10:00
Paul Sokolovsky f09d2ec608 unittest: Support both test classes and class instances.
And for clarity, rename runner function run_class() -> run_suite().

Signed-off-by: Paul Sokolovsky <pfalcon@users.sourceforge.net>
2022-05-06 10:47:37 +10:00
Paul Sokolovsky d747b21fc6 unittest: Only treat callable fields as test methods.
Signed-off-by: Paul Sokolovsky <pfalcon@users.sourceforge.net>
2022-05-06 10:47:37 +10:00
Paul Sokolovsky c72ec5c029 unittest: TestSuite: Add undescore to internal field, self._tests.
To avoid possible name clashes.

Signed-off-by: Paul Sokolovsky <pfalcon@users.sourceforge.net>
2022-05-06 10:47:37 +10:00
Paul Sokolovsky dc788f4e50 unittest: Reinstate useful debugger helper.
Signed-off-by: Paul Sokolovsky <pfalcon@users.sourceforge.net>
2022-05-06 10:47:37 +10:00
Paul Sokolovsky dedfe2dcd4 unittest: Add assertLessEqual, assertGreaterEqual methods.
As used by CPython testsuite.
2022-05-06 10:47:37 +10:00
Paul Sokolovsky a57b575020 unittest: AssertRaisesContext: Store exception value as self.exception.
For tests to check. This feature is used by CPython stdlib tests.
2022-05-06 10:47:37 +10:00
Paul Sokolovsky 965e25ce89 unittest: test_unittest: Typo fix. 2022-05-06 10:47:37 +10:00
Paul Sokolovsky fca89f65c7 unittest: test_unittest: Add test for .assertRaises(AssertionError).
Make sure that not raising AssertionError from tested function is properly
caught.
2022-05-06 10:47:37 +10:00
sss 669d343feb unittest: Allow to catch AssertionError with assertRaises().
Without this change, current implementaiton produces a false positive
result for AssertionError type.

Example of falsely passing test code:

def test(a, b):
    assert a > 10
    assert b > 10

self.assertRaises(AssertionError, test, 20, 20)
2022-05-06 10:47:37 +10:00
Paul Sokolovsky 663a3d6c54 unittest: test_unittest.py: Fix typo in method name. 2022-05-06 10:47:37 +10:00
Andrew Leech 7d4d02edfc unittest: Log failure tracebacks at test end.
Store traceback details for each test failure and log to console at the
end of the test, like CPython version of the module does.
2022-05-06 10:47:37 +10:00
Andrew Leech a9cd99ce2d unittest: Allow passing module name or instance into unittest.main() 2022-05-06 10:47:37 +10:00
Jim Mussared fa13cbbc8b all: Run black over all code.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2021-05-27 15:50:04 +10:00
Jim Mussared 1a28fe84e8 top: Move modules into python-stdlib, unix-ffi, or micropython. 2021-05-27 15:41:08 +10:00