summaryrefslogtreecommitdiff
path: root/tests/scripts/python
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2017-10-10 08:23:34 +0200
committerSébastien Helleu <flashcode@flashtux.org>2017-10-10 08:23:34 +0200
commit9ac3097679ea17de4d977368ed0cb2e0d3cc9b89 (patch)
treea34d0211289990ff0915306019d44c23a63412a0 /tests/scripts/python
parentbfb8499d610a066b8f70c92a745b78fef5ff047a (diff)
downloadweechat-9ac3097679ea17de4d977368ed0cb2e0d3cc9b89.zip
tests: fix sort of Unparse classes on line number
Diffstat (limited to 'tests/scripts/python')
-rwxr-xr-xtests/scripts/python/unparse.py47
1 files changed, 28 insertions, 19 deletions
diff --git a/tests/scripts/python/unparse.py b/tests/scripts/python/unparse.py
index 25d6234fa..7484941e4 100755
--- a/tests/scripts/python/unparse.py
+++ b/tests/scripts/python/unparse.py
@@ -50,6 +50,8 @@ class UnparsePython(object):
the script to test WeeChat scripting API).
"""
+ __lineno__ = inspect.currentframe().f_lineno
+
def __init__(self, output=sys.stdout):
self.output = output
self.indent_string = ' ' * 4
@@ -309,6 +311,8 @@ class UnparsePerl(UnparsePython):
the script to test WeeChat scripting API).
"""
+ __lineno__ = inspect.currentframe().f_lineno
+
def _ast_assign(self, node):
"""Add an AST Assign in output."""
self.add(
@@ -465,6 +469,8 @@ class UnparseRuby(UnparsePython):
the script to test WeeChat scripting API).
"""
+ __lineno__ = inspect.currentframe().f_lineno
+
def _ast_attribute(self, node):
"""Add an AST Attribute in output."""
self.add(
@@ -537,6 +543,8 @@ class UnparseLua(UnparsePython):
the script to test WeeChat scripting API).
"""
+ __lineno__ = inspect.currentframe().f_lineno
+
def __init__(self, *args, **kwargs):
super(UnparseLua, self).__init__(*args, **kwargs)
self.cmpop = {
@@ -638,6 +646,8 @@ class UnparseTcl(UnparsePython):
the script to test WeeChat scripting API).
"""
+ __lineno__ = inspect.currentframe().f_lineno
+
def __init__(self, *args, **kwargs):
super(UnparseTcl, self).__init__(*args, **kwargs)
self._call = 0
@@ -784,6 +794,8 @@ class UnparseGuile(UnparsePython):
the script to test WeeChat scripting API).
"""
+ __lineno__ = inspect.currentframe().f_lineno
+
def __init__(self, *args, **kwargs):
super(UnparseGuile, self).__init__(*args, **kwargs)
self.cmpop = {
@@ -955,6 +967,8 @@ class UnparseJavascript(UnparsePython):
the script to test WeeChat scripting API).
"""
+ __lineno__ = inspect.currentframe().f_lineno
+
def _ast_dict(self, node):
"""Add an AST Dict in output."""
self.add(
@@ -1015,6 +1029,8 @@ class UnparsePhp(UnparsePython):
the script to test WeeChat scripting API).
"""
+ __lineno__ = inspect.currentframe().f_lineno
+
def _ast_assign(self, node):
"""Add an AST Assign in output."""
self.add(
@@ -1141,25 +1157,18 @@ class UnparsePhp(UnparsePython):
def get_languages():
"""Return a list of supported languages: ['python', 'perl', ...]."""
- def linenumber_of_member(member):
- """Return the line number of a member."""
- try:
- # python 2
- return member[1].__init__.im_func.func_code.co_firstlineno
- except AttributeError:
- try:
- # python 3
- return member[1].__init__.__code__.co_firstlineno
- except AttributeError:
- return -1
-
- languages = []
- members = inspect.getmembers(sys.modules[__name__],
- predicate=inspect.isclass)
- members.sort(key=linenumber_of_member)
- for name, obj in members:
- if inspect.isclass(obj) and name.startswith('Unparse'):
- languages.append(name[7:].lower())
+ members = [
+ member
+ for member in inspect.getmembers(sys.modules[__name__],
+ predicate=inspect.isclass)
+ if inspect.isclass(member[1]) and member[0].startswith('Unparse')
+ ]
+
+ languages = [
+ name[7:].lower()
+ for name, obj in sorted(members,
+ key=lambda member: member[1].__lineno__)
+ ]
return languages