Commit a0166b87 authored by FichteFoll's avatar FichteFoll

Change the tests to only generate tests for all repositories when passed `--test-repositories`

(Also improve a debug message)
parent 650e94d8
...@@ -6,14 +6,16 @@ You can run this script directly or with `python -m unittest` from this or the ...@@ -6,14 +6,16 @@ You can run this script directly or with `python -m unittest` from this or the
root directory. For some reason `nosetests` does not pick up the generated tests root directory. For some reason `nosetests` does not pick up the generated tests
even though they are generated at load time. even though they are generated at load time.
However, only running the script directly will generate tests for all Arguments:
repositories in channel.json. This is to reduce the load time for every test run --test-repositories
by travis (and reduces unnecessary failures). Also generates tests for all repositories in `channel.json` (the http
ones).
""" """
import os import os
import re import re
import json import json
import sys
import unittest import unittest
from collections import OrderedDict from collections import OrderedDict
...@@ -21,6 +23,13 @@ from functools import wraps ...@@ -21,6 +23,13 @@ from functools import wraps
from urllib.request import urlopen from urllib.request import urlopen
from urllib.error import HTTPError from urllib.error import HTTPError
arglist = ['--test-repositories']
# Exctract used arguments form the commandline an strip them for unittest.main
userargs = [arg for arg in sys.argv if arg in arglist]
for arg in userargs:
if arg in sys.argv:
sys.argv.remove(arg)
################################################################################ ################################################################################
# Utilities # Utilities
...@@ -164,7 +173,7 @@ class TestContainer(object): ...@@ -164,7 +173,7 @@ class TestContainer(object):
def _test_package(self, include, data): def _test_package(self, include, data):
for k, v in data.items(): for k, v in data.items():
self.assertIn(k, self.package_key_types_map) self.assertIn(k, self.package_key_types_map)
self.assertIsInstance(v, self.package_key_types_map[k]) self.assertIsInstance(v, self.package_key_types_map[k], k)
if k in ('details', 'homepage', 'readme', 'issues', 'donate', if k in ('details', 'homepage', 'readme', 'issues', 'donate',
'buy'): 'buy'):
...@@ -263,9 +272,9 @@ class ChannelTests(TestContainer, unittest.TestCase): ...@@ -263,9 +272,9 @@ class ChannelTests(TestContainer, unittest.TestCase):
@classmethod @classmethod
def generate_repository_tests(cls): def generate_repository_tests(cls):
if __name__ != '__main__': if not "--test-repositories" in userargs:
# Do not generate tests for all repositories (those hosted online) # Only generate tests for all repositories (those hosted online)
# when testing with unittest's crawler; only when run directly. # when run with "--test-repositories" parameter.
return return
for repository in cls.j['repositories']: for repository in cls.j['repositories']:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment