Let's say I have a python function and dictionary as follows:
d = {"a": 1, "b": 2, "c": 3}
def foo(input):
return d[input]
Is there a way when I push my code to GitHub (presumably with some sort of continuous integration) to check that all calls of foo
only use one of the keys of d
as the input
argument, and if there is a call with an invalid argument, to flag it or raise an alert?
For example:
foo("a") # no flag
foo("d") # flag/alert
I know how I would raise an exception or ValueError
at runtime, but I'm looking for a CI solution to include in our GitHub workflow. Right now we are using Travis-CI for our custom tests and the standard CodeQL tests provided by LGTM. I looked into using custom CodeQL via LGTM, but I couldn't quite figure it out. I'd be fine implementing it in either of those continuous integrations or implementing a third.
we are in your wrkDir where your pythonFunction.py is, where your foo(input), d dict is inside. In that wrkDir create file tests.py:
In wrkDir run
expexted output:
The tests.py exit code is 0 (all tests succeeded), or none 0 if some test failed, so you can control your CI task accordingly,