From f0d1e99556b6963ce00d19b7decde3ab1c3c10ca Mon Sep 17 00:00:00 2001 From: John Hawkinson Date: Mon, 10 Oct 2016 21:45:15 -0400 Subject: [PATCH 1/2] [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. --- README.md | 2 +- test/test_download.py | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4debe15fe..d6308d2ed 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/test/test_download.py b/test/test_download.py index a3f1c0644..393bc590e 100644 --- a/test/test_download.py +++ b/test/test_download.py @@ -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() From 264cc256481e851f4011c452953f29fafb14e935 Mon Sep 17 00:00:00 2001 From: John Hawkinson Date: Mon, 10 Oct 2016 21:55:07 -0400 Subject: [PATCH 2/2] kill extra blank line --- test/test_download.py | 1 - 1 file changed, 1 deletion(-) diff --git a/test/test_download.py b/test/test_download.py index 393bc590e..5c393f59f 100644 --- a/test/test_download.py +++ b/test/test_download.py @@ -238,7 +238,6 @@ for n, test_case in enumerate(defs): i += 1 test_method.__name__ = str(tname) setattr(TestDownload, test_method.__name__, test_method) - del test_method if __name__ == '__main__':