diff --git a/requirements-dev.txt b/requirements-dev.txt new file mode 100644 index 00000000..82d42736 --- /dev/null +++ b/requirements-dev.txt @@ -0,0 +1,3 @@ +# compare blinka's implementation vs the stubs coming from CircuitPython's implementation +circuitpython-stubs +mypy diff --git a/requirements-dev.txt.license b/requirements-dev.txt.license new file mode 100644 index 00000000..cc693300 --- /dev/null +++ b/requirements-dev.txt.license @@ -0,0 +1,3 @@ +# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries +# +# SPDX-License-Identifier: MIT diff --git a/test/stubtest.py b/test/stubtest.py new file mode 100644 index 00000000..1270b19c --- /dev/null +++ b/test/stubtest.py @@ -0,0 +1,49 @@ +"""Compare Blinka's implementation vs CircuitPython's stubs. + +To do this, we use MyPy's stubtest... But we invoke it from this file, instead +of running it directly, so that we can set a specific target board and whatnot. Also +makes it easier to iterate the whole src/ folder and run the tool on each and every file. +""" + +import os +import sys +from pathlib import Path + +from mypy import stubtest + +SRC = Path(__file__).parent.parent / "src" +sys.argv = [ + "stubtest", + # run on all files + *(path.stem for path in SRC.glob("*.py")), + # shorter output (1 line instead of 5?) per error + "--concise", + # do not error about things on Blinka that arent on stubs + "--ignore-missing-stub", +] + +def main() -> int: + """Run tests and return 0 on success, 1 in error.""" + for target in [ + "BLINKA_OS_AGNOSTIC", + # add more things here ?? + ]: + msg = f"Running for: {target}" + print(msg, "=" * len(msg), sep="\n") + + os.environ["BLINKA_FORCECHIP"] = target + + # potentially some unittest.mock.patch or the like, to get code running + + # TODO(elpekenin): pass arguments to this script? eg --failfast to control + # whether this quitting is performed or not + ret = stubtest.main() + if ret != 0: + return ret + + # yay, no test failed + return 0 + + +if __name__ == "__main__": + sys.exit(main())