Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update scheme tests #8835

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
155 changes: 76 additions & 79 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,16 @@
import unittest

from functools import wraps
from urllib.request import urlopen
from urllib.error import HTTPError
from urllib.parse import urljoin

if sys.version_info >= (3,):
from urllib.request import urlopen
from urllib.error import HTTPError
from urllib.parse import urljoin

generator_method_type = 'method'
str_cls = str
else:
from . import unittest_compat
from urlparse import urljoin
from urllib2 import HTTPError, urlopen

unittest_compat.inject_into_unittest()
generator_method_type = 'instancemethod'
str_cls = unicode # NOQA (obviously undefined in Py3)
generator_method_type = 'method'


if hasattr(sys, 'argv'):
arglist = ['--test-repositories']
# Exctract used arguments form the commandline an strip them for
# Extract used arguments from commandline an strip them for
# unittest.main
userargs = [arg for arg in sys.argv if arg in arglist]
for arg in userargs:
Expand Down Expand Up @@ -129,7 +118,7 @@ def wrapper(self, method=method, params=params):
class CaseInsensitiveDict(dict):
@classmethod
def _k(cls, key):
return key.lower() if isinstance(key, str_cls) else key
return key.lower() if isinstance(key, str) else key

def __getitem__(self, key):
return super(CaseInsensitiveDict, self).__getitem__(self._k(key))
Expand Down Expand Up @@ -172,38 +161,38 @@ def setUpClass(cls):
# except for Pascal and Rust
# which only ship in ST3
default_packages = (
'ActionScript', 'AppleScript', 'ASP', 'Batch File',
'C#', 'C++', 'Clojure', 'Color Scheme - Default', 'CSS', 'D', 'Default',
'Diff', 'Erlang', 'Go', 'Graphviz', 'Groovy', 'Haskell', 'HTML', 'Java',
'JavaScript', 'Language - English', 'LaTeX', 'Lisp', 'Lua', 'Makefile',
'Markdown', 'Matlab', 'Objective-C', 'OCaml', 'Pascal', 'Perl', 'PHP',
'Python', 'R', 'Rails', 'Regular Expressions', 'RestructuredText',
'Ruby', 'Rust', 'Scala', 'ShellScript', 'SQL', 'TCL', 'Text', 'Textile',
'ActionScript', 'AppleScript', 'ASP', 'Batch File', 'Binary', 'C#',
'C++', 'Clojure', 'Color Scheme - Default', 'CSS', 'D', 'Default',
'Diff', 'Erlang', 'Git Formats', 'Go', 'Graphviz', 'Groovy',
'Haskell', 'HTML', 'Java', 'JavaScript', 'Language - English',
'LaTeX', 'Lisp', 'Lua', 'Makefile', 'Markdown', 'Matlab',
'Objective-C', 'OCaml', 'Pascal', 'Perl', 'PHP', 'Python', 'R',
'Rails', 'Regular Expressions', 'RestructuredText', 'Ruby', 'Rust',
'Scala', 'ShellScript', 'SQL', 'TCL', 'Text', 'Textile',
'Theme - Default', 'Vintage', 'XML', 'YAML'
)

rel_b_reg = r'''^ (https:// github\.com/ [^/]+/ [^/]+
|https:// bitbucket\.org/ [^/]+/ [^/]+
|https:// gitlab\.com/ [^/]+/ [^/]+
rel_b_reg = r'''^ ( https:// bitbucket\.org / [^/#?]+ / [^/#?]+
| https:// github\.com / [^/#?]+ / [^/#?]+
| https:// gitlab\.com / [^/#?]+ / [^/#?]+
) $'''
# Strip multilines for better debug info on failures
rel_b_reg = ' '.join(map(str.strip, rel_b_reg.split()))
release_base_regex = re.compile(rel_b_reg, re.X)

pac_d_reg = r'''^ (https:// github\.com/ [^/]+/ [^/]+ (/tree/ .+ (?<!/)
|/)? (?<!\.git)
|https:// bitbucket\.org/ [^/]+/ [^/]+ (/src/ .+ (?<!/)
|\#tags
|/)?
|https:// gitlab\.com/ [^/]+/ [^/]+ (/-/tree/ .+ (?<!/)
|/)? (?<!\.git)
pac_d_reg = r'''^ ( https:// bitbucket\.org/ [^/#?]+/ [^/#?]+
( /src/ [^#?]*[^/#?] | \#tags | / )?
| https:// github\.com/ [^/#?]+/ [^/#?]+
(?<!\.git) ( /tree/ [^#?]*[^/#?] | / )?
| https:// gitlab\.com/ [^/#?]+/ [^/#?]+
(?<!\.git) ( /-/tree/ [^#?]*[^/#?] | / )?
) $'''
pac_d_reg = ' '.join(map(str.strip, pac_d_reg.split()))
package_details_regex = re.compile(pac_d_reg, re.X)

def _test_repository_keys(self, include, data):
keys = ('schema_version', 'packages', 'dependencies', 'includes')
self.assertTrue(2 <= len(data) <= 4, "Unexpected number of keys")
keys = ("$schema", 'schema_version', 'packages', 'dependencies', 'includes')
self.assertTrue(2 <= len(data) <= len(keys), "Unexpected number of keys")
self.assertIn('schema_version', data)
self.assertEqual(data['schema_version'], '3.0.0')

Expand Down Expand Up @@ -236,7 +225,7 @@ def _test_dependency_names(self, include, data):

# Check package order
self.assertEqual(repo_dependency_names,
sorted(repo_dependency_names, key=str_cls.lower),
sorted(repo_dependency_names, key=str.lower),
"Dependencies must be sorted alphabetically")

def _test_repository_package_names(self, include, data):
Expand Down Expand Up @@ -284,7 +273,7 @@ def _test_repository_package_names(self, include, data):

# Check package order
self.assertEqual(repo_package_names,
sorted(repo_package_names, key=str_cls.lower),
sorted(repo_package_names, key=str.lower),
"Packages must be sorted alphabetically (by name)")

def _test_indentation(self, filename, contents):
Expand All @@ -293,16 +282,16 @@ def _test_indentation(self, filename, contents):
"Indent must be tabs in line %d" % (i + 1))

package_key_types_map = {
'name': str_cls,
'details': str_cls,
'description': str_cls,
'name': str,
'details': str,
'description': str,
'releases': list,
'homepage': str_cls,
'author': (str_cls, list),
'readme': str_cls,
'issues': str_cls,
'donate': (str_cls, type(None)),
'buy': str_cls,
'homepage': str,
'author': (str, list),
'readme': str,
'issues': str,
'donate': (str, type(None)),
'buy': str,
'previous_names': list,
'labels': list
}
Expand Down Expand Up @@ -372,12 +361,12 @@ def _test_package(self, include, data):
'provided' % key)

dependency_key_types_map = {
'name': str_cls,
'description': str_cls,
'name': str,
'description': str,
'releases': list,
'issues': str_cls,
'load_order': str_cls,
'author': str_cls
'issues': str,
'load_order': str,
'author': str
}

def _test_dependency(self, include, data):
Expand All @@ -400,26 +389,26 @@ def _test_dependency(self, include, data):
self.assertIn(key, data, '%r is required for dependencies' % key)

pck_release_key_types_map = {
'base': str_cls,
'tags': (bool, str_cls),
'branch': str_cls,
'sublime_text': str_cls,
'platforms': (list, str_cls),
'dependencies': (list, str_cls),
'version': str_cls,
'date': str_cls,
'url': str_cls
'base': str,
'tags': (bool, str),
'branch': str,
'sublime_text': str,
'platforms': (list, str),
'dependencies': (list, str),
'version': str,
'date': str,
'url': str
}

dep_release_key_types_map = {
'base': str_cls,
'tags': (bool, str_cls),
'branch': str_cls,
'sublime_text': str_cls,
'platforms': (list, str_cls),
'version': str_cls,
'sha256': str_cls,
'url': str_cls
'base': str,
'tags': (bool, str),
'branch': str,
'sublime_text': str,
'platforms': (list, str),
'version': str,
'sha256': str,
'url': str
}

def _test_release(self, package_name, data, dependency, main_repo=True):
Expand Down Expand Up @@ -516,7 +505,7 @@ def check_release_key_values(self, data, dependency):
'or of the form `<version> - <version>`')

elif k == 'platforms':
if isinstance(v, str_cls):
if isinstance(v, str):
v = [v]
for plat in v:
self.assertRegex(plat,
Expand All @@ -525,10 +514,10 @@ def check_release_key_values(self, data, dependency):
self.assertCountEqual(v, list(set(v)),
"Specifying the same platform multiple times is redundant")

if (("osx-x32" in v and "osx-x64" in v) or
("windows-x32" in v and "windows-x64" in v) or
("linux-x32" in v and "linux-x64" in v)):
self.fail("Specifying both x32 and x64 architectures is redundant")
if (("osx-x32" in v and "osx-x64" in v and "osx-arm64" in v) or
("windows-x32" in v and "windows-x64" in v and "windows-arm64" in v) or
("linux-x32" in v and "linux-x64" in v and "linux-arm64" in v)):
self.fail("Specifying all of x32, x64 and arm64 architectures is redundant")

self.assertFalse(set(["osx", "windows", "linux"]) == set(v),
'"osx, windows, linux" are similar to (and should be replaced by) "*"')
Expand All @@ -547,7 +536,7 @@ def check_release_key_values(self, data, dependency):
elif k == 'tags':
self.assertTrue(bool(v),
'"tags" must be `true` or a string of length>0')
if isinstance(v, str_cls):
if isinstance(v, str):
self.assertFalse(v == "true",
'It is unlikely to specify the prefix '
'"true" use not the boolean `true`')
Expand Down Expand Up @@ -741,14 +730,22 @@ def tearDownClass(cls):
print("Repositories skipped: %s" % dict(cls.skipped_repositories))

def test_channel_keys(self):
allowed_keys = ("$schema", 'repositories', 'schema_version')
keys = sorted(self.j.keys())
self.assertEqual(keys, ['repositories', 'schema_version'])

self.assertTrue(2 <= len(keys) <= len(allowed_keys), "Unexpected number of keys")

for k in keys:
self.assertIn(k, allowed_keys, "Unexpected key")

self.assertIn('schema_version', keys)
self.assertEqual(self.j['schema_version'], '3.0.0')

self.assertIn('repositories', keys)
self.assertIsInstance(self.j['repositories'], list)

for repo in self.j['repositories']:
self.assertIsInstance(repo, str_cls)
self.assertIsInstance(repo, str)

def test_indentation(self):
return self._test_indentation('channel.json', self.source)
Expand All @@ -759,7 +756,7 @@ def test_channel_repositories(self):
self.assertRegex(repo, r"^(\.|https://)",
"Repositories must be relative urls or use the "
"HTTPS protocol")
self.assertEqual(repos, sorted(repos, key=str_cls.lower),
self.assertEqual(repos, sorted(repos, key=str.lower),
"Repositories must be sorted alphabetically")

@classmethod
Expand Down Expand Up @@ -811,7 +808,7 @@ def test_repository_keys(self):
self.assertIsInstance(self.j['includes'], list)

for include in self.j['includes']:
self.assertIsInstance(include, str_cls)
self.assertIsInstance(include, str)

def test_indentation(self):
return self._test_indentation('repository.json', self.source)
Expand Down
96 changes: 0 additions & 96 deletions tests/unittest_compat.py

This file was deleted.