[test_download]: -m regexp to run matching tests

Run test modules whose name matches the given regexp.
This is quick-and-dirty, there's probably a better way,
but the TestSuite system is really complicated and this is
super-easy.
This commit is contained in:
John Hawkinson 2016-10-10 21:45:15 -04:00
parent 1dd58e14d8
commit f0d1e99556
2 changed files with 13 additions and 2 deletions

View File

@ -987,7 +987,7 @@ After you have ensured this site is distributing it's content legally, you can f
}
```
5. Add an import in [`youtube_dl/extractor/extractors.py`](https://github.com/rg3/youtube-dl/blob/master/youtube_dl/extractor/extractors.py).
6. Run `python test/test_download.py TestDownload.test_YourExtractor`. This *should fail* at first, but you can continually re-run it until you're done. If you decide to add more than one test, then rename ``_TEST`` to ``_TESTS`` and make it into a list of dictionaries. The tests will then be named `TestDownload.test_YourExtractor`, `TestDownload.test_YourExtractor_1`, `TestDownload.test_YourExtractor_2`, etc.
6. Run `python test/test_download.py -m YourExtractor` to run all tests for YourExtractor. This *should fail* at first, but you can continually re-run it until you're done. If you decide to add more than one test, then rename ``_TEST`` to ``_TESTS`` and make it into a list of dictionaries. The tests will then be named `TestDownload.test_YourExtractor`, `TestDownload.test_YourExtractor_1`, `TestDownload.test_YourExtractor_2`, etc. You run individual tests with `python test/test_download.py TestDownload.test_YourExtractor`, etc.
7. Have a look at [`youtube_dl/extractor/common.py`](https://github.com/rg3/youtube-dl/blob/master/youtube_dl/extractor/common.py) for possible helper methods and a [detailed description of what your extractor should and may return](https://github.com/rg3/youtube-dl/blob/master/youtube_dl/extractor/common.py#L74-L252). Add tests and code for as many as you want.
8. Make sure your code follows [youtube-dl coding conventions](#youtube-dl-coding-conventions) and check the code with [flake8](https://pypi.python.org/pypi/flake8). Also make sure your code works under all [Python](http://www.python.org/) versions claimed supported by youtube-dl, namely 2.6, 2.7, and 3.2+.
9. When the tests pass, [add](http://git-scm.com/docs/git-add) the new files and [commit](http://git-scm.com/docs/git-commit) them and [push](http://git-scm.com/docs/git-push) the result, like this:

View File

@ -4,6 +4,7 @@ from __future__ import unicode_literals
# Allow direct execution
import os
import re
import sys
import unittest
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
@ -217,18 +218,28 @@ def generator(test_case):
return test_template
module = ""
if __name__ == '__main__':
import sys
if len(sys.argv)>2 and sys.argv[1] == '-m':
module = sys.argv[2]
del sys.argv[2], sys.argv[1]
# And add them to TestDownload
for n, test_case in enumerate(defs):
test_method = generator(test_case)
if not re.match(module, test_case['name']):
continue
tname = 'test_' + str(test_case['name'])
i = 1
while hasattr(TestDownload, tname):
tname = 'test_%s_%d' % (test_case['name'], i)
i += 1
test_method.__name__ = str(tname)
setattr(TestDownload, test_method.__name__, test_method)
del test_method
del test_method
if __name__ == '__main__':
unittest.main()