scripts: test.py/bench.py: Some small tweaks
- Delayed defines/permutations assignment until after generation. Just a bit of code smell. - Expanded all __eq__, __ne__, __lt__, __gt__, etc magic methods, just to minimize surprises in the future.
This commit is contained in:
+41
-11
@@ -98,10 +98,6 @@ class BenchCase:
|
|||||||
|
|
||||||
self.internal = bool(self.in_)
|
self.internal = bool(self.in_)
|
||||||
|
|
||||||
# figure out defines and build possible permutations
|
|
||||||
self.defines = set()
|
|
||||||
self.permutations = []
|
|
||||||
|
|
||||||
# defines can be a dict or a list or dicts
|
# defines can be a dict or a list or dicts
|
||||||
suite_defines = config.pop('suite_defines', {})
|
suite_defines = config.pop('suite_defines', {})
|
||||||
if not isinstance(suite_defines, list):
|
if not isinstance(suite_defines, list):
|
||||||
@@ -149,14 +145,17 @@ class BenchCase:
|
|||||||
else:
|
else:
|
||||||
return [v]
|
return [v]
|
||||||
|
|
||||||
# build possible permutations
|
# figure out defines and build possible permutations
|
||||||
|
defines__ = set()
|
||||||
|
permutations__ = []
|
||||||
for suite_defines_ in suite_defines:
|
for suite_defines_ in suite_defines:
|
||||||
self.defines |= suite_defines_.keys()
|
defines__ |= suite_defines_.keys()
|
||||||
for defines_ in defines:
|
for defines_ in defines:
|
||||||
self.defines |= defines_.keys()
|
defines__ |= defines_.keys()
|
||||||
self.permutations.append({
|
permutations__.append({k: parse_define(v)
|
||||||
k: parse_define(v)
|
|
||||||
for k, v in (suite_defines_ | defines_).items()})
|
for k, v in (suite_defines_ | defines_).items()})
|
||||||
|
self.defines = defines__
|
||||||
|
self.permutations = permutations__
|
||||||
|
|
||||||
for k in config.keys():
|
for k in config.keys():
|
||||||
print('%swarning:%s in %s, found unused key %r' % (
|
print('%swarning:%s in %s, found unused key %r' % (
|
||||||
@@ -169,11 +168,27 @@ class BenchCase:
|
|||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<BenchCase %s>' % self.name
|
return '<BenchCase %s>' % self.name
|
||||||
|
|
||||||
def __lt__(self, other):
|
|
||||||
# sort by suite, lineno, and name
|
# sort by suite, lineno, and name
|
||||||
|
def __eq__(self, other):
|
||||||
|
return ((self.suite, self.lineno, self.name)
|
||||||
|
== (other.suite, other.lineno, other.name))
|
||||||
|
|
||||||
|
def __ne__(self, other):
|
||||||
|
return not self.__eq__(other)
|
||||||
|
|
||||||
|
def __lt__(self, other):
|
||||||
return ((self.suite, self.lineno, self.name)
|
return ((self.suite, self.lineno, self.name)
|
||||||
< (other.suite, other.lineno, other.name))
|
< (other.suite, other.lineno, other.name))
|
||||||
|
|
||||||
|
def __gt__(self, other):
|
||||||
|
return self.__class__.__lt__(other, self)
|
||||||
|
|
||||||
|
def __le__(self, other):
|
||||||
|
return not self.__gt__(other)
|
||||||
|
|
||||||
|
def __ge__(self, other):
|
||||||
|
return not self.__lt__(other)
|
||||||
|
|
||||||
def isin(self, path):
|
def isin(self, path):
|
||||||
return (self.in_ is not None
|
return (self.in_ is not None
|
||||||
and os.path.normpath(self.in_)
|
and os.path.normpath(self.in_)
|
||||||
@@ -286,12 +301,27 @@ class BenchSuite:
|
|||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<BenchSuite %s>' % self.name
|
return '<BenchSuite %s>' % self.name
|
||||||
|
|
||||||
def __lt__(self, other):
|
|
||||||
# sort by name
|
# sort by name
|
||||||
#
|
#
|
||||||
# note we override this with a topological sort during compilation
|
# note we override this with a topological sort during compilation
|
||||||
|
def __eq__(self, other):
|
||||||
|
return self.name == other.name
|
||||||
|
|
||||||
|
def __ne__(self, other):
|
||||||
|
return not self.__eq__(other)
|
||||||
|
|
||||||
|
def __lt__(self, other):
|
||||||
return self.name < other.name
|
return self.name < other.name
|
||||||
|
|
||||||
|
def __gt__(self, other):
|
||||||
|
return self.__class__.__lt__(other, self)
|
||||||
|
|
||||||
|
def __le__(self, other):
|
||||||
|
return not self.__gt__(other)
|
||||||
|
|
||||||
|
def __ge__(self, other):
|
||||||
|
return not self.__lt__(other)
|
||||||
|
|
||||||
def isin(self, path):
|
def isin(self, path):
|
||||||
return (self.in_ is not None
|
return (self.in_ is not None
|
||||||
and os.path.normpath(self.in_)
|
and os.path.normpath(self.in_)
|
||||||
|
|||||||
+41
-11
@@ -104,10 +104,6 @@ class TestCase:
|
|||||||
config.pop('suite_reentrant', False))
|
config.pop('suite_reentrant', False))
|
||||||
self.fuzz = bool(self.fuzz_)
|
self.fuzz = bool(self.fuzz_)
|
||||||
|
|
||||||
# figure out defines and build possible permutations
|
|
||||||
self.defines = set()
|
|
||||||
self.permutations = []
|
|
||||||
|
|
||||||
# defines can be a dict or a list or dicts
|
# defines can be a dict or a list or dicts
|
||||||
suite_defines = config.pop('suite_defines', {})
|
suite_defines = config.pop('suite_defines', {})
|
||||||
if not isinstance(suite_defines, list):
|
if not isinstance(suite_defines, list):
|
||||||
@@ -155,14 +151,17 @@ class TestCase:
|
|||||||
else:
|
else:
|
||||||
return [v]
|
return [v]
|
||||||
|
|
||||||
# build possible permutations
|
# figure out defines and build possible permutations
|
||||||
|
defines__ = set()
|
||||||
|
permutations__ = []
|
||||||
for suite_defines_ in suite_defines:
|
for suite_defines_ in suite_defines:
|
||||||
self.defines |= suite_defines_.keys()
|
defines__ |= suite_defines_.keys()
|
||||||
for defines_ in defines:
|
for defines_ in defines:
|
||||||
self.defines |= defines_.keys()
|
defines__ |= defines_.keys()
|
||||||
self.permutations.append({
|
permutations__.append({k: parse_define(v)
|
||||||
k: parse_define(v)
|
|
||||||
for k, v in (suite_defines_ | defines_).items()})
|
for k, v in (suite_defines_ | defines_).items()})
|
||||||
|
self.defines = defines__
|
||||||
|
self.permutations = permutations__
|
||||||
|
|
||||||
for k in config.keys():
|
for k in config.keys():
|
||||||
print('%swarning:%s in %s, found unused key %r' % (
|
print('%swarning:%s in %s, found unused key %r' % (
|
||||||
@@ -175,11 +174,27 @@ class TestCase:
|
|||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<TestCase %s>' % self.name
|
return '<TestCase %s>' % self.name
|
||||||
|
|
||||||
def __lt__(self, other):
|
|
||||||
# sort by suite, lineno, and name
|
# sort by suite, lineno, and name
|
||||||
|
def __eq__(self, other):
|
||||||
|
return ((self.suite, self.lineno, self.name)
|
||||||
|
== (other.suite, other.lineno, other.name))
|
||||||
|
|
||||||
|
def __ne__(self, other):
|
||||||
|
return not self.__eq__(other)
|
||||||
|
|
||||||
|
def __lt__(self, other):
|
||||||
return ((self.suite, self.lineno, self.name)
|
return ((self.suite, self.lineno, self.name)
|
||||||
< (other.suite, other.lineno, other.name))
|
< (other.suite, other.lineno, other.name))
|
||||||
|
|
||||||
|
def __gt__(self, other):
|
||||||
|
return self.__class__.__lt__(other, self)
|
||||||
|
|
||||||
|
def __le__(self, other):
|
||||||
|
return not self.__gt__(other)
|
||||||
|
|
||||||
|
def __ge__(self, other):
|
||||||
|
return not self.__lt__(other)
|
||||||
|
|
||||||
def isin(self, path):
|
def isin(self, path):
|
||||||
return (self.in_ is not None
|
return (self.in_ is not None
|
||||||
and os.path.normpath(self.in_)
|
and os.path.normpath(self.in_)
|
||||||
@@ -298,12 +313,27 @@ class TestSuite:
|
|||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<TestSuite %s>' % self.name
|
return '<TestSuite %s>' % self.name
|
||||||
|
|
||||||
def __lt__(self, other):
|
|
||||||
# sort by name
|
# sort by name
|
||||||
#
|
#
|
||||||
# note we override this with a topological sort during compilation
|
# note we override this with a topological sort during compilation
|
||||||
|
def __eq__(self, other):
|
||||||
|
return self.name == other.name
|
||||||
|
|
||||||
|
def __ne__(self, other):
|
||||||
|
return not self.__eq__(other)
|
||||||
|
|
||||||
|
def __lt__(self, other):
|
||||||
return self.name < other.name
|
return self.name < other.name
|
||||||
|
|
||||||
|
def __gt__(self, other):
|
||||||
|
return self.__class__.__lt__(other, self)
|
||||||
|
|
||||||
|
def __le__(self, other):
|
||||||
|
return not self.__gt__(other)
|
||||||
|
|
||||||
|
def __ge__(self, other):
|
||||||
|
return not self.__lt__(other)
|
||||||
|
|
||||||
def isin(self, path):
|
def isin(self, path):
|
||||||
return (self.in_ is not None
|
return (self.in_ is not None
|
||||||
and os.path.normpath(self.in_)
|
and os.path.normpath(self.in_)
|
||||||
|
|||||||
Reference in New Issue
Block a user