well, once you know programming in one language, switching to a new programming language is like learning to speak a new language, i.e. relatively straightforward and mostly requiring to learn vocab/grammar. Itās figuring out the idioms that is hard and it takes a long time, and usually you canāt learn it from books - you need to expose yourself to situations where those are used/needed.
Each programming language usually has straightforward easy things loop/branch/etc., and then hard things that require understanding the language internals (frames/gc/namespaces/etc.). some languages make easy things easy and hard thing possible, other languages make hard things hard or not always doable. But since Iām new to python, I wonāt pass any judgements yet, until I master it better.
Thatās why I asked whether perhaps someone knows how to make a function behave like a built-in. So far I didnāt find a way. It seems that import and fully qualified functions are the only way to go.
I added some fuzzy matching functionality to search through the tests folder and places the function is called.
This is just in case nothing is returned from this_tests
Also returning a skeleton test function. If you guys think itās a good idea, we could expand on this and add asserts and fill in variables from the function parameters.
Hope itās along the lines of what you two were thinking. I can continue iterating
Thatās a brilliant idea. I didnāt think of it. I guess we just need to control the number of hits with auto-discovery, since some functions might be used in 50% of all tests.
Also returning a skeleton test function. If you guys think itās a good idea, we could expand on this and add asserts and fill in variables from the function parameters.
That one Iām not sure what to say, if the skeleton contains just the name of the function, Iām not sure how much of a headstart that provides. Perhaps for some people having a skeleton may trigger an incentive to fill the void? In which case Iām all for it. Nothing to lose.
Should we call the main function show_test? so we will have show_doc and show_test?
And I think other than you coming up with all kinds of cool ways making this little project even cooler we still need to know in what format do you want test_this() to fuel show_test to bridge the two sides? it can be a plain file, json, or any other format that you think will be the easiest.
@ashaw@stas find here the json file I generated with the code snippets, see below: Idea is per API we will have a list of tests, so several tests could be registered per API.
This is generated with json.dump, looks a little odd when opening the file. So wanted to write doc_test and see how this all works.
But lets coordinate this here ā¦ what ever file makes sense. We do not necessarily need json also.
think its a great idea, we link the git area from the repo how to contribute and give 1-2sentences on guidelines to write a test. But what do you mean with āasserts and fill in variables from the function parameters?ā You mean we can further kind of generate skeletons? That would be cool.
we might want to add a parameter Direct / Ancillary Tests and Skeleton to the file TestAPIRegister.json I generate, if we let the discovery also come up with this. But then we also need this when registering with this_tests. So maybe we leave the categories to the dicovery and per default in this_tests only generate tests of category Direct.
Good, except please drop āfile: /Users/bherudek/Desktop/fastaigits/fastai-doctest/tests/ā from that file. It has to be relative to tests/ and not hardcoding paths which will be different for each person.
wrt:
matching = [s for s in set(sys.argv) if "test_" in s]
this: if "test_" in sys.argv: ...
will do the same
But Iām concerned that someone may have ātest_ā in their path, prior to fastai/tests/test_ and also we may run it as:
cd tests
pytest test_...
so matching on tests/test_ wonāt work either.
Therefore I think we need to use a regex with your original code instead and match for r'test_\w+\.py'.
and FYI, I will not be weighing in on any other suggestions to do more until this simple task is finished and integrated. But, of course, feel free to discuss and brainstorm, but please donāt @ me. Thank you.
@Benudek can you also include the line number on where this_test happens?
Either the line number of the parent function or the line number of this_test is fine.
I like the guidelines part - if no tests show up, we can display the skeleton and guideline.
Further down the line - I was thinking of similar to tools/build-docs - generate a skeleton test.py file or append the test function if the file already exists. We could fill in as much as possible since we know the parameter types and the return type
Cool works for me! Current format looks good to me.
One minor change - can the metadata be a dictionary instead of array?
fastai.train.lr_findā: [ āfile: /Users/bherudek/Desktop/fastaigits/fastai-doctest/tests/test_train.pyā ]
That wonāt always be the case, please refer to the spec - it could be called anywhere in the script. So you need to lookup the function itās called from (def ā¦) and get the line number from its data.
using your function to get the parent function and lineno (btw the lineno is e.g. 16 where the function starts at 17 - I guess you are aware and count e.g. with 0) Surprised I couldnāt solve this with the frame, but guess there is a reason you wrote that function ;-).
havenāt changed that array yet: For one API we might (probably will) have several tests - at least it is a logical possibility and wouldnāt want to overwrite than other tests. So, arrays is fine?
one small change in conftest following @stas comment on regex
To Dos, provided this works for you:
consider: get parent func to common util (or I import your class), so far copied the func