€•( Œsphinx.addnodes”Œdocument”“”)�”}”(Œ rawsource”Œ ”Œchildren”]”Œdocutils.nodes”Œsection”“”)�”}”(hhh]”(h Œtitle”“”)�”}”(hŒ5Systematic code examples: a guided tour of Transcrypt”h]”h ŒText”“”Œ5Systematic code examples: a guided tour of Transcrypt”…”�”}”(hhŒparent”hhhŒsource”NŒline”NubaŒ
attributes”}”(Œids”]”Œclasses”]”Œnames”]”Œdupnames”]”Œbackrefs”]”uŒtagname”hhhhhhŒ]/home/jac/active/geatec/transcrypt/Transcrypt/transcrypt/docs/sphinx/supported_constructs.rst”hKubh Œ paragraph”“”)�”}”(hX½ One ready-to-run code example is worth more than ten lengthy descriptions. The *autotest and demo suite*, that is part of the distribution, is a collection of sourcecode fragments called *testlets*. These testlets are used for automated regression testing of Transcrypt against CPython.
Since they systematically cover all language constructs, they are also very effective as a learning tool. The testlets are arranged alphabetically by subject.”h]”(hŒOOne ready-to-run code example is worth more than ten lengthy descriptions. The ”…”�”}”(hŒOOne ready-to-run code example is worth more than ten lengthy descriptions. The ”hh.hhhNhNubh Œemphasis”“”)�”}”(hŒ*autotest and demo suite*”h]”hŒautotest and demo suite”…”�”}”(hhhh9ubah}”(h ]”h"]”h$]”h&]”h(]”uh*h7hh.ubhŒS, that is part of the distribution, is a collection of sourcecode fragments called ”…”�”}”(hŒS, that is part of the distribution, is a collection of sourcecode fragments called ”hh.hhhNhNubh8)�”}”(hŒ
*testlets*”h]”hŒtestlets”…”�”}”(hhhhLubah}”(h ]”h"]”h$]”h&]”h(]”uh*h7hh.ubhŒø. These testlets are used for automated regression testing of Transcrypt against CPython.
Since they systematically cover all language constructs, they are also very effective as a learning tool. The testlets are arranged alphabetically by subject.”…”�”}”(hŒø. These testlets are used for automated regression testing of Transcrypt against CPython.
Since they systematically cover all language constructs, they are also very effective as a learning tool. The testlets are arranged alphabetically by subject.”hh.hhhNhNubeh}”(h ]”h"]”h$]”h&]”h(]”uh*h,hh+hKhhhhubh Œ container”“”)�”}”(hhh]”(h Œcaption”“”)�”}”(hŒ(Autotest: Transcrypt autotest demo suite”h]”hŒ(Autotest: Transcrypt autotest demo suite”…”�”}”(hhnhhlubah}”(h ]”h"]”h$]”h&]”h(]”uh*hjhh+hKhhgubh Œ
literal_block”“”)�”}”(hXJ from org.transcrypt.stubs.browser import __pragma__
import org.transcrypt.autotester
import arguments
import attribs_by_name
import builtin_super
import byte_arrays
import callable_test
import classes
import complex_numbers
import conditional_expressions
import control_structures
import dashed_numbers
import data_classes
import data_structures
import decorators
import dict_comprehensions
import dictionaries
import div_issues
import div_pulls
import docstrings
import exceptions
import executable_comments
import extended_slices
import fstrings
import general_functions
import globals_function
import indices_and_slices
import iterators_and_generators
import lambda_functions
import list_comprehensions
import local_classes
import metaclasses
import method_and_class_decorators
import module_builtin
import module_cmath
if __pragma__ ('defined', 'undefined'):
import module_collections
import module_datetime
import module_itertools
import module_math
import module_unicodedata
import modules
import nonlocals
import operator_overloading
import properties
import proxies
import reprtest
import set_comprehensions
import simple_and_augmented_assignment
if __pragma__ ('defined', '__sform__'):
import string_format
import truthyness
import tuple_assignment
autoTester = org.transcrypt.autotester.AutoTester ()
autoTester.run (arguments, 'arguments')
autoTester.run (attribs_by_name, 'attribs_by_name')
autoTester.run (builtin_super, 'builtin_super')
autoTester.run (byte_arrays, 'byte_arrays')
autoTester.run (callable_test, 'callable')
autoTester.run (classes, 'classes')
autoTester.run (complex_numbers, 'complex_numbers')
autoTester.run (conditional_expressions, 'conditional_expressions')
autoTester.run (control_structures, 'control_structures')
autoTester.run (dashed_numbers, 'dashed_numbers')
autoTester.run (data_classes, 'data_classes')
autoTester.run (data_structures, 'data_structures')
autoTester.run (decorators, 'decorators')
autoTester.run (dict_comprehensions, 'dict_comprehensions')
autoTester.run (dictionaries, 'dictionaries')
autoTester.run (div_issues, 'div_issues')
autoTester.run (div_pulls, 'div_pulls')
autoTester.run (docstrings, 'docstrings')
autoTester.run (exceptions, 'exceptions')
autoTester.run (executable_comments, 'executable_comments')
autoTester.run (extended_slices, 'extended_slices')
autoTester.run (fstrings, 'fstrings')
autoTester.run (general_functions, 'general_functions')
autoTester.run (globals_function, 'globals_function')
autoTester.run (indices_and_slices, 'indices_and_slices')
autoTester.run (iterators_and_generators, 'iterators_and_generators')
autoTester.run (lambda_functions, 'lambda_functions')
autoTester.run (list_comprehensions, 'list_comprehensions')
autoTester.run (local_classes, 'local_classes')
autoTester.run (metaclasses, 'metaclasses')
autoTester.run (method_and_class_decorators, 'method_and_class_decorators')
autoTester.run (module_builtin, 'module_builtin')
autoTester.run (module_cmath, 'module_cmath')
if __pragma__ ('defined', 'undefined'):
autoTester.run (module_collections, 'module_collections')
autoTester.run (module_datetime, 'module_datetime')
autoTester.run (module_itertools, 'module_itertools')
autoTester.run (module_math, 'module_math')
autoTester.run (module_unicodedata, 'module_unicodedata')
autoTester.run (modules, 'modules')
autoTester.run (nonlocals, 'nonlocals')
autoTester.run (operator_overloading, 'operator_overloading')
autoTester.run (properties, 'properties')
autoTester.run (reprtest, 'repr_str')
autoTester.run (proxies, 'proxies')
autoTester.run (set_comprehensions, 'set_comprehensions')
autoTester.run (simple_and_augmented_assignment, 'simple_and_augmented_assignment')
if __pragma__ ('defined', '__sform__'):
autoTester.run (string_format, 'string_format')
autoTester.run (truthyness, 'truthyness')
autoTester.run (tuple_assignment, 'tuple_assignment')
autoTester.done ()
”h]”hXJ from org.transcrypt.stubs.browser import __pragma__
import org.transcrypt.autotester
import arguments
import attribs_by_name
import builtin_super
import byte_arrays
import callable_test
import classes
import complex_numbers
import conditional_expressions
import control_structures
import dashed_numbers
import data_classes
import data_structures
import decorators
import dict_comprehensions
import dictionaries
import div_issues
import div_pulls
import docstrings
import exceptions
import executable_comments
import extended_slices
import fstrings
import general_functions
import globals_function
import indices_and_slices
import iterators_and_generators
import lambda_functions
import list_comprehensions
import local_classes
import metaclasses
import method_and_class_decorators
import module_builtin
import module_cmath
if __pragma__ ('defined', 'undefined'):
import module_collections
import module_datetime
import module_itertools
import module_math
import module_unicodedata
import modules
import nonlocals
import operator_overloading
import properties
import proxies
import reprtest
import set_comprehensions
import simple_and_augmented_assignment
if __pragma__ ('defined', '__sform__'):
import string_format
import truthyness
import tuple_assignment
autoTester = org.transcrypt.autotester.AutoTester ()
autoTester.run (arguments, 'arguments')
autoTester.run (attribs_by_name, 'attribs_by_name')
autoTester.run (builtin_super, 'builtin_super')
autoTester.run (byte_arrays, 'byte_arrays')
autoTester.run (callable_test, 'callable')
autoTester.run (classes, 'classes')
autoTester.run (complex_numbers, 'complex_numbers')
autoTester.run (conditional_expressions, 'conditional_expressions')
autoTester.run (control_structures, 'control_structures')
autoTester.run (dashed_numbers, 'dashed_numbers')
autoTester.run (data_classes, 'data_classes')
autoTester.run (data_structures, 'data_structures')
autoTester.run (decorators, 'decorators')
autoTester.run (dict_comprehensions, 'dict_comprehensions')
autoTester.run (dictionaries, 'dictionaries')
autoTester.run (div_issues, 'div_issues')
autoTester.run (div_pulls, 'div_pulls')
autoTester.run (docstrings, 'docstrings')
autoTester.run (exceptions, 'exceptions')
autoTester.run (executable_comments, 'executable_comments')
autoTester.run (extended_slices, 'extended_slices')
autoTester.run (fstrings, 'fstrings')
autoTester.run (general_functions, 'general_functions')
autoTester.run (globals_function, 'globals_function')
autoTester.run (indices_and_slices, 'indices_and_slices')
autoTester.run (iterators_and_generators, 'iterators_and_generators')
autoTester.run (lambda_functions, 'lambda_functions')
autoTester.run (list_comprehensions, 'list_comprehensions')
autoTester.run (local_classes, 'local_classes')
autoTester.run (metaclasses, 'metaclasses')
autoTester.run (method_and_class_decorators, 'method_and_class_decorators')
autoTester.run (module_builtin, 'module_builtin')
autoTester.run (module_cmath, 'module_cmath')
if __pragma__ ('defined', 'undefined'):
autoTester.run (module_collections, 'module_collections')
autoTester.run (module_datetime, 'module_datetime')
autoTester.run (module_itertools, 'module_itertools')
autoTester.run (module_math, 'module_math')
autoTester.run (module_unicodedata, 'module_unicodedata')
autoTester.run (modules, 'modules')
autoTester.run (nonlocals, 'nonlocals')
autoTester.run (operator_overloading, 'operator_overloading')
autoTester.run (properties, 'properties')
autoTester.run (reprtest, 'repr_str')
autoTester.run (proxies, 'proxies')
autoTester.run (set_comprehensions, 'set_comprehensions')
autoTester.run (simple_and_augmented_assignment, 'simple_and_augmented_assignment')
if __pragma__ ('defined', '__sform__'):
autoTester.run (string_format, 'string_format')
autoTester.run (truthyness, 'truthyness')
autoTester.run (tuple_assignment, 'tuple_assignment')
autoTester.done ()
”…”�”}”(hhhh|ubah}”(h ]”h"]”h$]”h&]”h(]”Œsource”Œk/home/jac/active/geatec/transcrypt/Transcrypt/transcrypt/development/automated_tests/transcrypt/autotest.py”Œ xml:space”Œpreserve”Œforce”‰Œhighlight_args”}”Œlinenostart”Ksuh*hzhh+hKhhgubeh}”(h ]”Œid1”ah"]”Œliteral-block-wrapper”ah$]”h&]”h(]”Œ
literal_block”ˆuh*hehhhhhhhNubh Œtarget”“”)�”}”(hŒ.. _autotest_arguments:”h]”h}”(h ]”h"]”h$]”h&]”h(]”Œrefid”Œautotest-arguments”uh*h›hKhhhhhh+ubh)�”}”(hhh]”(h)�”}”(hŒPArguments: \*\*kwargs, \*args, defaults, at call and def time, also for lambda's”h]”hŒRArguments: * *kwargs, *args, defaults, at call and def time, also for lambda’s”…”�”}”(hŒPArguments: \*\*kwargs, \*args, defaults, at call and def time, also for lambda's”hh¬hhhNhNubah}”(h ]”h"]”h$]”h&]”h(]”uh*hhh©hhhh+hKubhf)�”}”(hhh]”(hk)�”}”(hŒTestlet: arguments”h]”hŒTestlet: arguments”…”�”}”(hhÀhh¾ubah}”(h ]”h"]”h$]”h&]”h(]”uh*hjhh+hKhh»ubh{)�”}”(hXD from org.transcrypt.stubs.browser import __pragma__
__pragma__ ('kwargs')
class A:
def __init__ (self, x = 123, y = 456, *args, m, n = 456, **kwargs):
self.x = x
self.y = y
self.args = args
self.m = m
self.n = n
self.kwargs = kwargs
self.extra = 'hello'
def f (self, autoTester):
autoTester.check (self.x, self.y, self.args, self.m, self.n, self.kwargs, self.extra)
class B (A):
def __init__ (self, x, y = -1, *args, m = -2, n, **kwargs):
A.__init__ (self, y, x, *args, m = n, n = m, **kwargs)
class C:
__pragma__ ('nokwargs')
def tricky (self, *args):
return args
__pragma__ ('kwargs')
def run (autoTester):
def f (x, y = -1, *args, m = -2, n, **kwargs):
# BEGIN issue 203, kwargs turned into real dict
autoTester.check ('#203', kwargs.__class__.__name__)
autoTester.check ('#203', sorted (kwargs.keys ()))
# END issue 203
def f2 (x, y = -3, *args, m = -4, n, **kwargs):
autoTester.check (x, y, args, m, n, kwargs)
f2 (11, 22, 1010, 2020, m = 100100, n = 200200, p = 10001000, q = 20002000)
autoTester.check (x, y, args, m, n, kwargs)
f (1, 2, 10, 20, m = 100, n = 200, p = 1000, q = 2000)
b = B (3, 4, 30, 40, m = 300, n = 400, p = 3000, q = 4000)
b.f (autoTester)
def g (*args, **kwargs):
autoTester.check (args, kwargs)
g (*(1, 2, 3), **{'p': 'aP', 'q': 'aQ', 'r': 'anR'})
(lambda x, y = -1, *args, m = -2, n, **kwargs: autoTester.check (x, y, args, m, n, kwargs)) (1, 2, 8, 16, m = 128, n = 256.3, p = 1024.3, q = 2048.3)
autoTester.check (C () .tricky (* range (4)))
autoTester.check ('{}-{}'.format (1, 3, 5, 7, 9))
autoTester.check ('{}-{}'.format (* range (4)))
”h]”hXD from org.transcrypt.stubs.browser import __pragma__
__pragma__ ('kwargs')
class A:
def __init__ (self, x = 123, y = 456, *args, m, n = 456, **kwargs):
self.x = x
self.y = y
self.args = args
self.m = m
self.n = n
self.kwargs = kwargs
self.extra = 'hello'
def f (self, autoTester):
autoTester.check (self.x, self.y, self.args, self.m, self.n, self.kwargs, self.extra)
class B (A):
def __init__ (self, x, y = -1, *args, m = -2, n, **kwargs):
A.__init__ (self, y, x, *args, m = n, n = m, **kwargs)
class C:
__pragma__ ('nokwargs')
def tricky (self, *args):
return args
__pragma__ ('kwargs')
def run (autoTester):
def f (x, y = -1, *args, m = -2, n, **kwargs):
# BEGIN issue 203, kwargs turned into real dict
autoTester.check ('#203', kwargs.__class__.__name__)
autoTester.check ('#203', sorted (kwargs.keys ()))
# END issue 203
def f2 (x, y = -3, *args, m = -4, n, **kwargs):
autoTester.check (x, y, args, m, n, kwargs)
f2 (11, 22, 1010, 2020, m = 100100, n = 200200, p = 10001000, q = 20002000)
autoTester.check (x, y, args, m, n, kwargs)
f (1, 2, 10, 20, m = 100, n = 200, p = 1000, q = 2000)
b = B (3, 4, 30, 40, m = 300, n = 400, p = 3000, q = 4000)
b.f (autoTester)
def g (*args, **kwargs):
autoTester.check (args, kwargs)
g (*(1, 2, 3), **{'p': 'aP', 'q': 'aQ', 'r': 'anR'})
(lambda x, y = -1, *args, m = -2, n, **kwargs: autoTester.check (x, y, args, m, n, kwargs)) (1, 2, 8, 16, m = 128, n = 256.3, p = 1024.3, q = 2048.3)
autoTester.check (C () .tricky (* range (4)))
autoTester.check ('{}-{}'.format (1, 3, 5, 7, 9))
autoTester.check ('{}-{}'.format (* range (4)))
”…”�”}”(hhhhÌubah}”(h ]”h"]”h$]”h&]”h(]”Œsource”Œu/home/jac/active/geatec/transcrypt/Transcrypt/transcrypt/development/automated_tests/transcrypt/arguments/__init__.py”hŒh�hމh�}”h‘Ksuh*hzhh+hKhh»ubeh}”(h ]”Œid2”ah"]”h–ah$]”h&]”h(]”Œ
literal_block”ˆuh*hehh©hhhhhNubeh}”(h ]”(ŒEarguments-kwargs-args-defaults-at-call-and-def-time-also-for-lambda-s”h¨eh"]”h$]”(ŒMarguments: **kwargs, *args, defaults, at call and def time, also for lambda's”Œautotest_arguments”eh&]”h(]”uh*h
hhhhhh+hKŒexpect_referenced_by_name”}”hëh�sŒexpect_referenced_by_id”}”h¨h�subh)�”}”(hhh]”(h)�”}”(hŒ3Attribute access by name: getattr, setattr, hasattr”h]”hŒ3Attribute access by name: getattr, setattr, hasattr”…”�”}”(hh÷hhõhhhNhNubah}”(h ]”h"]”h$]”h&]”h(]”uh*hhhòhhhh+hKubhf)�”}”(hhh]”(hk)�”}”(hŒTestlet: attribs_by_name”h]”hŒTestlet: attribs_by_name”…”�”}”(hj hj ubah}”(h ]”h"]”h$]”h&]”h(]”uh*hjhh+hKhj ubh{)�”}”(hXˆ class A:
def __init__ (self):
self.s = 'hello'
a = A ()
def run (autoTester):
autoTester.check (a.s, getattr (a, 's'))
setattr (a, 's', 'goodbye')
autoTester.check (a.s, getattr (a, 's'))
setattr (a, 't', 'exists')
autoTester.check (hasattr (a, 't'), a.t, getattr (a, 't'))
delattr (a, 't')
autoTester.check (hasattr (a, 't'))
”h]”hXˆ class A:
def __init__ (self):
self.s = 'hello'
a = A ()
def run (autoTester):
autoTester.check (a.s, getattr (a, 's'))
setattr (a, 's', 'goodbye')
autoTester.check (a.s, getattr (a, 's'))
setattr (a, 't', 'exists')
autoTester.check (hasattr (a, 't'), a.t, getattr (a, 't'))
delattr (a, 't')
autoTester.check (hasattr (a, 't'))
”…”�”}”(hhhj ubah}”(h ]”h"]”h$]”h&]”h(]”Œsource”Œ{/home/jac/active/geatec/transcrypt/Transcrypt/transcrypt/development/automated_tests/transcrypt/attribs_by_name/__init__.py”hŒh�hމh�}”h‘Ksuh*hzhh+hKhj ubeh}”(h ]”Œid3”ah"]”h–ah$]”h&]”h(]”Œ
literal_block”ˆuh*hehhòhhhhhNubeh}”(h ]”Œ0attribute-access-by-name-getattr-setattr-hasattr”ah"]”h$]”Œ3attribute access by name: getattr, setattr, hasattr”ah&]”h(]”uh*h
hhhhhh+hKubh)�”}”(hhh]”(h)�”}”(hŒ3Attribute proxies by name: __getattr__, __setattr__”h]”hŒ3Attribute proxies by name: __getattr__, __setattr__”…”�”}”(hj: hj8 hhhNhNubah}”(h ]”h"]”h$]”h&]”h(]”uh*hhj5 hhhh+hKubhf)�”}”(hhh]”(hk)�”}”(hŒTestlet: proxies”h]”hŒTestlet: proxies”…”�”}”(hjK hjI ubah}”(h ]”h"]”h$]”h&]”h(]”uh*hjhh+hKhjF ubh{)�”}”(hX from org.transcrypt.stubs.browser import __pragma__
def run (autoTester):
class CodedStore:
def __init__ (self):
try:
__pragma__ ('js', '{}', 'self ["__dict__"] = {}')
except:
pass
def __setattr__ (self, name, message):
self.__dict__ ['_' + name] = 'coded_' + message
def __getattr__ (self, name):
return 'decoded_' + self.__dict__ ['_' + name]
def peek (self, name):
return self.__dict__ ['_' + name]
s = CodedStore ()
s.john = 'brown'
s.mary = 'white'
autoTester.check (s.peek ('john'))
autoTester.check (s.peek ('mary'))
autoTester.check (s.john)
autoTester.check (s.mary)
'''
The code above produces the following output:
'coded_brown'
'coded_white'
'decoded_coded_brown'
'decoded_coded_white'
'''
class A:
def __init__ (self):
self.p = 1
self.q = 2
class B (A):
def __getattr__ (self, name):
return 'Faked {}'.format (name)
class C (A):
def __setattr__ (self, name, value):
autoTester.check ('Set faked {}'.format (name))
A.__setattr__ (self, name, value)
# Needed for CPython, inherited from class 'object'
# Transcrypt doesn't need it, if there's no __setattrib__ it will just use self [name] = value
class D (B, C):
pass
a = A ()
b = B ()
c = C ()
d = D ()
autoTester.check (a.p, a.q)
a.p = 3
autoTester.check (a.p, a.q)
autoTester.check (b.p, b.q, b.r, b.s)
b.p = 4
b.r = 5
autoTester.check (b.p, b.q, b.r, b.s)
autoTester.check (c.p, c.q)
c.p = 6
c.q = 7
autoTester.check (c.p, c.q)
autoTester.check (d.p, d.q, d.r, d.s)
d.p = 8
d.q = 9
d.r = 10
d.s = 11
autoTester.check (d.p, d.q, d.r, d.s)
# Issue 587, code as utilized by pjbonestro
autoTester.check ("Issue 587")
class Element():
def __init__(self):
self.message = "Goodbye"
def sayBye(self):
autoTester.check (self.message)
class Wrapper():
def __init__ (self, element):
self.element = element
def __setattr__ (self, name, value):
""" set attribute on element if it already has the attribute """
if name != "element" and hasattr(self.element, name):
setattr(self.element, name, value)
else:
self.__dict__[name] = value
def __getattr__ (self, name):
""" get attribute from element if this object doesn't have the attribute """
result = getattr(self.element, name)
# if result is a function, bind self.element to it
if hasattr(result, 'call') and hasattr(result, 'bind'):
result = result.bind(self.element)
return result
def sayHello(self):
autoTester.check("Hello")
return self
e = Element()
w = Wrapper(e)
#
# Usage
#
e.sayBye()
w.sayBye() # call functions on e, using w
# and method chaining should work:
w.sayHello().sayBye()
w.message = "Bye" # set attributes on e, using w
e.sayBye()
w.sayBye() # call functions on e, using w
# and method chaining should work:
w.sayHello().sayBye()
autoTester.check ("End issue 587")
# End of issue 587
”h]”hX from org.transcrypt.stubs.browser import __pragma__
def run (autoTester):
class CodedStore:
def __init__ (self):
try:
__pragma__ ('js', '{}', 'self ["__dict__"] = {}')
except:
pass
def __setattr__ (self, name, message):
self.__dict__ ['_' + name] = 'coded_' + message
def __getattr__ (self, name):
return 'decoded_' + self.__dict__ ['_' + name]
def peek (self, name):
return self.__dict__ ['_' + name]
s = CodedStore ()
s.john = 'brown'
s.mary = 'white'
autoTester.check (s.peek ('john'))
autoTester.check (s.peek ('mary'))
autoTester.check (s.john)
autoTester.check (s.mary)
'''
The code above produces the following output:
'coded_brown'
'coded_white'
'decoded_coded_brown'
'decoded_coded_white'
'''
class A:
def __init__ (self):
self.p = 1
self.q = 2
class B (A):
def __getattr__ (self, name):
return 'Faked {}'.format (name)
class C (A):
def __setattr__ (self, name, value):
autoTester.check ('Set faked {}'.format (name))
A.__setattr__ (self, name, value)
# Needed for CPython, inherited from class 'object'
# Transcrypt doesn't need it, if there's no __setattrib__ it will just use self [name] = value
class D (B, C):
pass
a = A ()
b = B ()
c = C ()
d = D ()
autoTester.check (a.p, a.q)
a.p = 3
autoTester.check (a.p, a.q)
autoTester.check (b.p, b.q, b.r, b.s)
b.p = 4
b.r = 5
autoTester.check (b.p, b.q, b.r, b.s)
autoTester.check (c.p, c.q)
c.p = 6
c.q = 7
autoTester.check (c.p, c.q)
autoTester.check (d.p, d.q, d.r, d.s)
d.p = 8
d.q = 9
d.r = 10
d.s = 11
autoTester.check (d.p, d.q, d.r, d.s)
# Issue 587, code as utilized by pjbonestro
autoTester.check ("Issue 587")
class Element():
def __init__(self):
self.message = "Goodbye"
def sayBye(self):
autoTester.check (self.message)
class Wrapper():
def __init__ (self, element):
self.element = element
def __setattr__ (self, name, value):
""" set attribute on element if it already has the attribute """
if name != "element" and hasattr(self.element, name):
setattr(self.element, name, value)
else:
self.__dict__[name] = value
def __getattr__ (self, name):
""" get attribute from element if this object doesn't have the attribute """
result = getattr(self.element, name)
# if result is a function, bind self.element to it
if hasattr(result, 'call') and hasattr(result, 'bind'):
result = result.bind(self.element)
return result
def sayHello(self):
autoTester.check("Hello")
return self
e = Element()
w = Wrapper(e)
#
# Usage
#
e.sayBye()
w.sayBye() # call functions on e, using w
# and method chaining should work:
w.sayHello().sayBye()
w.message = "Bye" # set attributes on e, using w
e.sayBye()
w.sayBye() # call functions on e, using w
# and method chaining should work:
w.sayHello().sayBye()
autoTester.check ("End issue 587")
# End of issue 587
”…”�”}”(hhhjW ubah}”(h ]”h"]”h$]”h&]”h(]”Œsource”Œs/home/jac/active/geatec/transcrypt/Transcrypt/transcrypt/development/automated_tests/transcrypt/proxies/__init__.py”hŒh�hމh�}”h‘Ksuh*hzhh+hKhjF ubeh}”(h ]”Œid4”ah"]”h–ah$]”h&]”h(]”Œ
literal_block”ˆuh*hehj5 hhhhhNubeh}”(h ]”Œ)attribute-proxies-by-name-getattr-setattr”ah"]”h$]”Œ3attribute proxies by name: __getattr__, __setattr__”ah&]”h(]”uh*h
hhhhhh+hKubh)�”}”(hhh]”(h)�”}”(hŒ%Bytes and bytearrays: initial support”h]”hŒ%Bytes and bytearrays: initial support”…”�”}”(hj} hj{ hhhNhNubah}”(h ]”h"]”h$]”h&]”h(]”uh*hhjx hhhh+hK$ubhf)�”}”(hhh]”(hk)�”}”(hŒTestlet: byte_arrays”h]”hŒTestlet: byte_arrays”…”�”}”(hjŽ hjŒ ubah}”(h ]”h"]”h$]”h&]”h(]”uh*hjhh+hK&hj‰ ubh{)�”}”(hXþ def run (autoTester):
b = b'bike'
s = bytes ('shop', 'utf8')
e = b''
bb = bytearray ([0, 1, 2, 3, 4])
bc = bytes ((5, 6, 7, 8, 9))
# __pragma__ ('opov')
bps = b + b'pump' + s
bps3 = 3 * bps + b'\0'
aBps3 = bps * 3 + b'\0'
l = [1, 2, 3] + [4, 5, 6]
# __pragma__ ('noopov')
def formatCheck (aBytes):
autoTester.check ([int (aByte) for aByte in aBytes])
formatCheck (b)
formatCheck (s)
formatCheck (e)
formatCheck (bb)
formatCheck (bc)
formatCheck (bps)
formatCheck (bps3)
formatCheck (aBps3)
# __pragma__ ('opov')
formatCheck (bb + bc)
formatCheck (bytearray ('ding', 'utf8') + b'dang' + bytes ('dong', 'utf8'))
# __pragma__ ('noopov')
formatCheck (l)”h]”hXþ def run (autoTester):
b = b'bike'
s = bytes ('shop', 'utf8')
e = b''
bb = bytearray ([0, 1, 2, 3, 4])
bc = bytes ((5, 6, 7, 8, 9))
# __pragma__ ('opov')
bps = b + b'pump' + s
bps3 = 3 * bps + b'\0'
aBps3 = bps * 3 + b'\0'
l = [1, 2, 3] + [4, 5, 6]
# __pragma__ ('noopov')
def formatCheck (aBytes):
autoTester.check ([int (aByte) for aByte in aBytes])
formatCheck (b)
formatCheck (s)
formatCheck (e)
formatCheck (bb)
formatCheck (bc)
formatCheck (bps)
formatCheck (bps3)
formatCheck (aBps3)
# __pragma__ ('opov')
formatCheck (bb + bc)
formatCheck (bytearray ('ding', 'utf8') + b'dang' + bytes ('dong', 'utf8'))
# __pragma__ ('noopov')
formatCheck (l)”…”�”}”(hhhjš ubah}”(h ]”h"]”h$]”h&]”h(]”Œsource”Œw/home/jac/active/geatec/transcrypt/Transcrypt/transcrypt/development/automated_tests/transcrypt/byte_arrays/__init__.py”hŒh�hމh�}”h‘Ksuh*hzhh+hK&hj‰ ubeh}”(h ]”Œid5”ah"]”h–ah$]”h&]”h(]”Œ
literal_block”ˆuh*hehjx hhhhhNubeh}”(h ]”Œ$bytes-and-bytearrays-initial-support”ah"]”h$]”Œ%bytes and bytearrays: initial support”ah&]”h(]”uh*h
hhhhhh+hK$ubh)�”}”(hhh]”(h)�”}”(hŒ8Callable or not: using the callable () built-in function”h]”hŒ8Callable or not: using the callable () built-in function”…”�”}”(hjÀ hj¾ hhhNhNubah}”(h ]”h"]”h$]”h&]”h(]”uh*hhj» hhhh+hK+ubh-)�”}”(hŒ^The *callable (object)* built-in function will tell you if something supports the () operator.”h]”(hŒThe ”…”�”}”(hŒThe ”hjÌ hhhNhNubh8)�”}”(hŒ*callable (object)*”h]”hŒcallable (object)”…”�”}”(hhhjÕ ubah}”(h ]”h"]”h$]”h&]”h(]”uh*h7hjÌ ubhŒG built-in function will tell you if something supports the () operator.”…”�”}”(hŒG built-in function will tell you if something supports the () operator.”hjÌ hhhNhNubeh}”(h ]”h"]”h$]”h&]”h(]”uh*h,hh+hK-hj» hhubhf)�”}”(hhh]”(hk)�”}”(hŒTestlet: callable_test”h]”hŒTestlet: callable_test”…”�”}”(hjó hjñ ubah}”(h ]”h"]”h$]”h&]”h(]”uh*hjhh+hK/hjî ubh{)�”}”(hX^ # Callable built-in method unit tests
from org.transcrypt.stubs.browser import __pragma__
def run(test):
"""
"""
def func(a,b):
return(a*b)
test.check( func(3,4) )
test.check( callable(func) )
for a in (True, False):
test.check( callable(a) )
a = 1
test.check( callable(a) )
a = 2.3
test.check( callable(a) )
a = "asdf"
test.check( callable(a) )
a = []
test.check( callable(a) )
a = [1,2,3,3]
test.check( callable(a) )
a = ["asdf", "qwer", "zxcv"]
test.check( callable(a) )
a = {"asdf" : 1, "qwer": 2}
test.check( callable(a) )
a = set([1,2])
test.check(callable(a))
__pragma__('opov')
class CallObj(object):
def __init__(self, r):
self._r = r
def __call__(self):
return(self._r)
test.check( callable(CallObj) )
obj = CallObj(2)
test.check(obj())
test.check( callable(obj) )
test.check( callable(obj._r) )
class NonCallObj(object):
def __init__(self, b):
self._b = b
def func(self):
return(self._b)
test.check( callable(NonCallObj) )
obj2 = NonCallObj(2)
test.check( callable(obj2) )
test.check( callable(obj2._b) )
test.check( callable(obj2.func) )
__pragma__('noopov')
class NonOpovNonCallObj(object):
"""
"""
def __init__(self, c):
self._c = c
def other(self, b):
return(self._c * b)
def _getC(self):
return(self._c)
def _setC(self, val):
self._c = val
C = property(_getC, _setC)
obj = NonOpovNonCallObj(4)
test.check( callable(obj) )
test.check( callable(obj.other) )
test.check( callable(obj._c) )
test.check( callable(obj.C) )
exc = Exception("asdf")
test.check( callable(exc) )
”h]”hX^ # Callable built-in method unit tests
from org.transcrypt.stubs.browser import __pragma__
def run(test):
"""
"""
def func(a,b):
return(a*b)
test.check( func(3,4) )
test.check( callable(func) )
for a in (True, False):
test.check( callable(a) )
a = 1
test.check( callable(a) )
a = 2.3
test.check( callable(a) )
a = "asdf"
test.check( callable(a) )
a = []
test.check( callable(a) )
a = [1,2,3,3]
test.check( callable(a) )
a = ["asdf", "qwer", "zxcv"]
test.check( callable(a) )
a = {"asdf" : 1, "qwer": 2}
test.check( callable(a) )
a = set([1,2])
test.check(callable(a))
__pragma__('opov')
class CallObj(object):
def __init__(self, r):
self._r = r
def __call__(self):
return(self._r)
test.check( callable(CallObj) )
obj = CallObj(2)
test.check(obj())
test.check( callable(obj) )
test.check( callable(obj._r) )
class NonCallObj(object):
def __init__(self, b):
self._b = b
def func(self):
return(self._b)
test.check( callable(NonCallObj) )
obj2 = NonCallObj(2)
test.check( callable(obj2) )
test.check( callable(obj2._b) )
test.check( callable(obj2.func) )
__pragma__('noopov')
class NonOpovNonCallObj(object):
"""
"""
def __init__(self, c):
self._c = c
def other(self, b):
return(self._c * b)
def _getC(self):
return(self._c)
def _setC(self, val):
self._c = val
C = property(_getC, _setC)
obj = NonOpovNonCallObj(4)
test.check( callable(obj) )
test.check( callable(obj.other) )
test.check( callable(obj._c) )
test.check( callable(obj.C) )
exc = Exception("asdf")
test.check( callable(exc) )
”…”�”}”(hhhjÿ ubah}”(h ]”h"]”h$]”h&]”h(]”Œsource”Œy/home/jac/active/geatec/transcrypt/Transcrypt/transcrypt/development/automated_tests/transcrypt/callable_test/__init__.py”hŒh�hމh�}”h‘Ksuh*hzhh+hK/hjî ubeh}”(h ]”Œid6”ah"]”h–ah$]”h&]”h(]”Œ
literal_block”ˆuh*hehj» hhhhhNubeh}”(h ]”Œ4callable-or-not-using-the-callable-built-in-function”ah"]”h$]”Œ8callable or not: using the callable () built-in function”ah&]”h(]”uh*h
hhhhhh+hK+ubh)�”}”(hhh]”(h)�”}”(hŒ?Classes: multiple inheritance and assignment of bound functions”h]”hŒ?Classes: multiple inheritance and assignment of bound functions”…”�”}”(hj% hj# hhhNhNubah}”(h ]”h"]”h$]”h&]”h(]”uh*hhj hhhh+hK4ubhf)�”}”(hhh]”(hk)�”}”(hŒTestlet: classes”h]”hŒTestlet: classes”…”�”}”(hj6 hj4 ubah}”(h ]”h"]”h$]”h&]”h(]”uh*hjhh+hK6hj1 ubh{)�”}”(hXc
def run (autoTester):
autoTester.check ('
General
')
class A:
p = 123
def __init__ (self, x):
self.x = x
autoTester.check (self.p)
def show (self, label):
autoTester.check ('A.show', label, self.x)
def show2 (self, label):
autoTester.check ('A.show2', label, self.x)
class B:
p, q = 456, 789
def __init__ (self, y):
autoTester.check ('In B constructor')
self.y = y
autoTester.check (self.p)
def show (self, label):
autoTester.check ('B.show', label, self.y)
class C (A, B):
def __init__ (self, x, y):
autoTester.check ('In C constructor')
A.__init__ (self, x)
B.__init__ (self, y)
def show (self, label):
A.show (self, label)
B.show (self, label)
autoTester.check ('C.show', label, self.x, self.y)
a = A (1001)
a.show ('america')
autoTester.check (A.p)
autoTester.check (a.p)
b = B (2002)
b.show ('russia')
autoTester.check (B.p)
autoTester.check (b.p)
autoTester.check (b.q)
autoTester.check (A.p)
autoTester.check (a.p)
c = C (3003, 4004)
c.show ('netherlands')
autoTester.check (C.p)
autoTester.check (c.p)
autoTester.check (c.q)
c.show2 ('amsterdam')
A.show2 (c, 'rotterdam')
show3 = c.show
show3 ('copy')
autoTester.check (hasattr (a, 'x'))
autoTester.check (hasattr (a, 'y'))
autoTester.check (hasattr (a, 'p'))
autoTester.check (hasattr (a, 'q'))
autoTester.check ('
Augmented isinstance and issubclass
')
# Augmented meaning: compatible with native JavaScript types
simpleTypes = (dict, list, A, B, C, bool, str, float, int, object)
tupleTypes = ((dict, list), (bool, int), (bool, A), (C, B), (B, object))
for i, types in enumerate ((simpleTypes, tupleTypes)):
for j, aType in enumerate (types):
for k, anObject in enumerate (({'a': 1}, [], a, C, c, C, b, True, 'a', 1, 1.2)):
autoTester.check (i, j, k, isinstance (anObject, aType))
if types == simpleTypes:
autoTester.check (i, j, k, isinstance (anObject, simpleTypes))
for i, types in enumerate ((simpleTypes, tupleTypes)):
for j, aType in enumerate (types):
for k, aClass in enumerate ((dict, list, A, C, B, bool, str, int, float)):
autoTester.check (i + 2, j, k, issubclass (aClass, aType))
if types == simpleTypes:
autoTester.check (i + 2, j, k, issubclass (aClass, simpleTypes))
autoTester.check ('
Method resolution order
')
def mro (aClass, result = None):
''' Recursively assemble method resolution order from all base classes'''
last = 0
if result is None:
result = [aClass]
last = 1
for aBase in aClass.__bases__:
if not aBase in result and aBase != object:
result.append (aBase)
mro (aBase, result)
if last and object in aClass.__bases__:
aRoot.append (object)
return result
autoTester.check ([aClass.__name__ for aClass in mro (C)])
”h]”hXc
def run (autoTester):
autoTester.check ('
General
')
class A:
p = 123
def __init__ (self, x):
self.x = x
autoTester.check (self.p)
def show (self, label):
autoTester.check ('A.show', label, self.x)
def show2 (self, label):
autoTester.check ('A.show2', label, self.x)
class B:
p, q = 456, 789
def __init__ (self, y):
autoTester.check ('In B constructor')
self.y = y
autoTester.check (self.p)
def show (self, label):
autoTester.check ('B.show', label, self.y)
class C (A, B):
def __init__ (self, x, y):
autoTester.check ('In C constructor')
A.__init__ (self, x)
B.__init__ (self, y)
def show (self, label):
A.show (self, label)
B.show (self, label)
autoTester.check ('C.show', label, self.x, self.y)
a = A (1001)
a.show ('america')
autoTester.check (A.p)
autoTester.check (a.p)
b = B (2002)
b.show ('russia')
autoTester.check (B.p)
autoTester.check (b.p)
autoTester.check (b.q)
autoTester.check (A.p)
autoTester.check (a.p)
c = C (3003, 4004)
c.show ('netherlands')
autoTester.check (C.p)
autoTester.check (c.p)
autoTester.check (c.q)
c.show2 ('amsterdam')
A.show2 (c, 'rotterdam')
show3 = c.show
show3 ('copy')
autoTester.check (hasattr (a, 'x'))
autoTester.check (hasattr (a, 'y'))
autoTester.check (hasattr (a, 'p'))
autoTester.check (hasattr (a, 'q'))
autoTester.check ('
Augmented isinstance and issubclass
')
# Augmented meaning: compatible with native JavaScript types
simpleTypes = (dict, list, A, B, C, bool, str, float, int, object)
tupleTypes = ((dict, list), (bool, int), (bool, A), (C, B), (B, object))
for i, types in enumerate ((simpleTypes, tupleTypes)):
for j, aType in enumerate (types):
for k, anObject in enumerate (({'a': 1}, [], a, C, c, C, b, True, 'a', 1, 1.2)):
autoTester.check (i, j, k, isinstance (anObject, aType))
if types == simpleTypes:
autoTester.check (i, j, k, isinstance (anObject, simpleTypes))
for i, types in enumerate ((simpleTypes, tupleTypes)):
for j, aType in enumerate (types):
for k, aClass in enumerate ((dict, list, A, C, B, bool, str, int, float)):
autoTester.check (i + 2, j, k, issubclass (aClass, aType))
if types == simpleTypes:
autoTester.check (i + 2, j, k, issubclass (aClass, simpleTypes))
autoTester.check ('
Method resolution order
')
def mro (aClass, result = None):
''' Recursively assemble method resolution order from all base classes'''
last = 0
if result is None:
result = [aClass]
last = 1
for aBase in aClass.__bases__:
if not aBase in result and aBase != object:
result.append (aBase)
mro (aBase, result)
if last and object in aClass.__bases__:
aRoot.append (object)
return result
autoTester.check ([aClass.__name__ for aClass in mro (C)])
”…”�”}”(hhhjB ubah}”(h ]”h"]”h$]”h&]”h(]”Œsource”Œs/home/jac/active/geatec/transcrypt/Transcrypt/transcrypt/development/automated_tests/transcrypt/classes/__init__.py”hŒh�hމh�}”h‘Ksuh*hzhh+hK6hj1 ubeh}”(h ]”Œid7”ah"]”h–ah$]”h&]”h(]”Œ
literal_block”ˆuh*hehj hhhhhNubeh}”(h ]”Œ>classes-multiple-inheritance-and-assignment-of-bound-functions”ah"]”h$]”Œ?classes: multiple inheritance and assignment of bound functions”ah&]”h(]”uh*h
hhhhhh+hK4ubh)�”}”(hhh]”(h)�”}”(hŒ2Complex numbers: Python's builtin complex datatype”h]”hŒ4Complex numbers: Python’s builtin complex datatype”…”�”}”(hjh hjf hhhNhNubah}”(h ]”h"]”h$]”h&]”h(]”uh*hhjc hhhh+hK;ubhf)�”}”(hhh]”(hk)�”}”(hŒTestlet: complex_numbers”h]”hŒTestlet: complex_numbers”…”�”}”(hjy hjw ubah}”(h ]”h"]”h$]”h&]”h(]”uh*hjhh+hK=hjt ubh{)�”}”(hXì from org.transcrypt.stubs.browser import __pragma__
def run (autoTester):
x = 567
y = -3
z = 5 * x + 2 * y
autoTester.check (x.conjugate () .real, x.conjugate () .imag)
autoTester.check (x, y, z)
__pragma__ ('opov')
a = 234 + 3j
b = 4 - 5j
c = complex (-6, 7)
d = 1
autoTester.check (a, b, c)
autoTester.check (d.conjugate () .real, d.conjugate () .imag)
t = 6 * x - 3 * y + 7 # Just to check, faster with 'noopov'
autoTester.check (t)
d = 2 * a
e = x * b
f = z + d + e
g = a / b
h = a - b
i = x - c
j = a - x
k = b + y
autoTester.check (d, e, f, round (g.real, 2), round (g.imag, 2), h, i, j, k)
__pragma__ ('noopov')
”h]”hXì from org.transcrypt.stubs.browser import __pragma__
def run (autoTester):
x = 567
y = -3
z = 5 * x + 2 * y
autoTester.check (x.conjugate () .real, x.conjugate () .imag)
autoTester.check (x, y, z)
__pragma__ ('opov')
a = 234 + 3j
b = 4 - 5j
c = complex (-6, 7)
d = 1
autoTester.check (a, b, c)
autoTester.check (d.conjugate () .real, d.conjugate () .imag)
t = 6 * x - 3 * y + 7 # Just to check, faster with 'noopov'
autoTester.check (t)
d = 2 * a
e = x * b
f = z + d + e
g = a / b
h = a - b
i = x - c
j = a - x
k = b + y
autoTester.check (d, e, f, round (g.real, 2), round (g.imag, 2), h, i, j, k)
__pragma__ ('noopov')
”…”�”}”(hhhj… ubah}”(h ]”h"]”h$]”h&]”h(]”Œsource”Œ{/home/jac/active/geatec/transcrypt/Transcrypt/transcrypt/development/automated_tests/transcrypt/complex_numbers/__init__.py”hŒh�hމh�}”h‘Ksuh*hzhh+hK=hjt ubeh}”(h ]”Œid8”ah"]”h–ah$]”h&]”h(]”Œ
literal_block”ˆuh*hehjc hhhhhNubeh}”(h ]”Œ1complex-numbers-python-s-builtin-complex-datatype”ah"]”h$]”Œ2complex numbers: python's builtin complex datatype”ah&]”h(]”uh*h
hhhhhh+hK;ubh)�”}”(hhh]”(h)�”}”(hŒ*Conditional expressions: simple and nested”h]”hŒ*Conditional expressions: simple and nested”…”�”}”(hj« hj© hhhNhNubah}”(h ]”h"]”h$]”h&]”h(]”uh*hhj¦ hhhh+hKBubhf)�”}”(hhh]”(hk)�”}”(hŒ Testlet: conditional_expressions”h]”hŒ Testlet: conditional_expressions”…”�”}”(hj¼ hjº ubah}”(h ]”h"]”h$]”h&]”h(]”uh*hjhh+hKDhj· ubh{)�”}”(hX, def f (x, b):
return x * x if b else x + x
def run (autoTester):
bools = (False, True)
for a in bools:
for b in bools:
autoTester.check (f (10 if a else 100, b))
for p in bools:
for q in bools:
for r in bools:
autoTester.check ('a' if p else 'b' if q else 'c' if r else 'd')
a = ((('e' if p else 'f') if q else 'g') if r else 'h')
b = ('i' if p else ('j' if q else ('k' if r else 'l')))
c = 'm' if (p if q else r) else 'n'
d = 'o' if p < q <= r else 'p'
autoTester.check (a, b, c, d)
odd = [x if x % 2 else x + 1 for x in range (10)]
noDuplicates = set (odd)
autoTester.check (odd, noDuplicates)
”h]”hX, def f (x, b):
return x * x if b else x + x
def run (autoTester):
bools = (False, True)
for a in bools:
for b in bools:
autoTester.check (f (10 if a else 100, b))
for p in bools:
for q in bools:
for r in bools:
autoTester.check ('a' if p else 'b' if q else 'c' if r else 'd')
a = ((('e' if p else 'f') if q else 'g') if r else 'h')
b = ('i' if p else ('j' if q else ('k' if r else 'l')))
c = 'm' if (p if q else r) else 'n'
d = 'o' if p < q <= r else 'p'
autoTester.check (a, b, c, d)
odd = [x if x % 2 else x + 1 for x in range (10)]
noDuplicates = set (odd)
autoTester.check (odd, noDuplicates)
”…”�”}”(hhhjÈ ubah}”(h ]”h"]”h$]”h&]”h(]”Œsource”Œƒ/home/jac/active/geatec/transcrypt/Transcrypt/transcrypt/development/automated_tests/transcrypt/conditional_expressions/__init__.py”hŒh�hމh�}”h‘Ksuh*hzhh+hKDhj· ubeh}”(h ]”Œid9”ah"]”h–ah$]”h&]”h(]”Œ
literal_block”ˆuh*hehj¦ hhhhhNubeh}”(h ]”Œ)conditional-expressions-simple-and-nested”ah"]”h$]”Œ*conditional expressions: simple and nested”ah&]”h(]”uh*h
hhhhhh+hKBubh)�”}”(hhh]”(h)�”}”(hŒOControl structures: for...else, while...else, if...elif...else, break, continue”h]”hŒOControl structures: for…else, while…else, if…elif…else, break, continue”…”�”}”(hjî hjì hhhNhNubah}”(h ]”h"]”h$]”h&]”h(]”uh*hhjé hhhh+hKIubhf)�”}”(hhh]”(hk)�”}”(hŒTestlet: control_structures”h]”hŒTestlet: control_structures”…”�”}”(hjÿ hjý ubah}”(h ]”h"]”h$]”h&]”h(]”uh*hjhh+hKKhjú ubh{)�”}”(hX¦ class ContextManagerExample:
def __init__ (self):
self.counter = 0
def __enter__ (self):
self.counter += 1
return self
def __exit__ (self, *args):
self.counter += 99
def run (autoTester):
# General control structure tests
for index in range (10):
autoTester.check (index)
for index in range (8, 16):
autoTester.check (index)
for index in range (8, 16, 2):
autoTester.check (index)
for index in range (10, 0, -1):
autoTester.check (index)
for index in range (16, 8, -2):
autoTester.check (index)
for animal in ('cat', 'dog', 'turtle', 'goldfish'):
autoTester.check (animal)
for index, square in enumerate ([x * x for x in range (10) if x % 2]):
for y in (1, 2, 3):
for z in (10, 20, 30):
autoTester.check (square + y, z )
vehicles = ['bike', 'train', 'boat', 'car', 'plane', 'bus']
for doBreak in (False, True):
for doContinue in (False, True):
for index in range (10):
for index2 in range (0, 100, 10):
if doBreak and index2 == 50:
autoTester.check ('break2')
break
if doContinue and index2 == 50:
autoTester.check ('continue2')
continue
else:
autoTester.check ('noBreak2')
if doBreak and index == 5:
autoTester.check ('break')
break
if doContinue and index == 5:
autoTester.check ('continue')
continue
else:
autoTester.check ('noBreak')
index = 0
while index < len (vehicles) and vehicles [index] != 'bus':
autoTester.check (index, vehicles [index])
if doBreak and vehicles [index] == 'car':
autoTester.check ('breakWhile')
break
if doContinue and vehicles [index] == 'car':
autoTester.check ('continueWhile')
index += 1
continue
index += 1
else:
autoTester.check ('noBreakWhile')
for vehicle in vehicles:
if vehicle == 'bike':
autoTester.check ('netherlands')
elif vehicle == 'car':
autoTester.check ('america')
elif vehicle == 'boat':
autoTester.check ('oceania')
else:
autoTester.check ('anywhere')
# Context manager tests
externalCounter1 = 0
with ContextManagerExample () as contextManagerExample1:
externalCounter1 += 1
autoTester.check ('ctx1', contextManagerExample1.counter, externalCounter1)
externalCounter2 = 0
with ContextManagerExample () as contextManagerExample2:
externalCounter2 += 1
contextManagerExample2.counter += 100
externalCounter3 = 0
with ContextManagerExample () as contextManagerExample3:
externalCounter3 += 1
contextManagerExample2.counter += 100
externalCounter3 += 2
contextManagerExample3.counter += 200
autoTester.check ('ctx3', contextManagerExample3.counter, externalCounter3)
externalCounter2 += 2
contextManagerExample2.counter += 200
autoTester.check ('ctx2', contextManagerExample2.counter, externalCounter2)
try:
externalCounter4 = 0
with ContextManagerExample () as contextManagerExample4:
externalCounter4 += 1
contextManagerExample4.counter += 100
externalCounter5 = 0
with ContextManagerExample () as contextManagerExample5:
externalCounter5 += 1
contextManagerExample5.counter += 100
raise Exception ()
externalCounter5 += 2
contextManagerExample5.counter += 200
externalCounter4 += 2
contextManagerExample4.counter += 200
except Exception as exception:
autoTester.check ('ctx6', exception)
finally:
autoTester.check ('ctx5', contextManagerExample5.counter, externalCounter5)
autoTester.check ('ctx4', contextManagerExample4.counter, externalCounter4)
# Multiple context managers in one clause
# $$$ The new parsers seems to treat them more like separate context managers.
# $$$ Or maybe it's a command line switch.
iterationCount = 0
with ContextManagerExample () as contextManagerExample5, ContextManagerExample () as contextManagerExample6:
iterationCount += 1
autoTester.check ('ctx7', iterationCount, contextManagerExample5.counter, contextManagerExample6.counter)
iterationCount = 0
with ContextManagerExample (), ContextManagerExample (), ContextManagerExample (), \
ContextManagerExample (), ContextManagerExample ():
iterationCount += 1
autoTester.check ('ctx8', iterationCount)
”h]”hX¦ class ContextManagerExample:
def __init__ (self):
self.counter = 0
def __enter__ (self):
self.counter += 1
return self
def __exit__ (self, *args):
self.counter += 99
def run (autoTester):
# General control structure tests
for index in range (10):
autoTester.check (index)
for index in range (8, 16):
autoTester.check (index)
for index in range (8, 16, 2):
autoTester.check (index)
for index in range (10, 0, -1):
autoTester.check (index)
for index in range (16, 8, -2):
autoTester.check (index)
for animal in ('cat', 'dog', 'turtle', 'goldfish'):
autoTester.check (animal)
for index, square in enumerate ([x * x for x in range (10) if x % 2]):
for y in (1, 2, 3):
for z in (10, 20, 30):
autoTester.check (square + y, z )
vehicles = ['bike', 'train', 'boat', 'car', 'plane', 'bus']
for doBreak in (False, True):
for doContinue in (False, True):
for index in range (10):
for index2 in range (0, 100, 10):
if doBreak and index2 == 50:
autoTester.check ('break2')
break
if doContinue and index2 == 50:
autoTester.check ('continue2')
continue
else:
autoTester.check ('noBreak2')
if doBreak and index == 5:
autoTester.check ('break')
break
if doContinue and index == 5:
autoTester.check ('continue')
continue
else:
autoTester.check ('noBreak')
index = 0
while index < len (vehicles) and vehicles [index] != 'bus':
autoTester.check (index, vehicles [index])
if doBreak and vehicles [index] == 'car':
autoTester.check ('breakWhile')
break
if doContinue and vehicles [index] == 'car':
autoTester.check ('continueWhile')
index += 1
continue
index += 1
else:
autoTester.check ('noBreakWhile')
for vehicle in vehicles:
if vehicle == 'bike':
autoTester.check ('netherlands')
elif vehicle == 'car':
autoTester.check ('america')
elif vehicle == 'boat':
autoTester.check ('oceania')
else:
autoTester.check ('anywhere')
# Context manager tests
externalCounter1 = 0
with ContextManagerExample () as contextManagerExample1:
externalCounter1 += 1
autoTester.check ('ctx1', contextManagerExample1.counter, externalCounter1)
externalCounter2 = 0
with ContextManagerExample () as contextManagerExample2:
externalCounter2 += 1
contextManagerExample2.counter += 100
externalCounter3 = 0
with ContextManagerExample () as contextManagerExample3:
externalCounter3 += 1
contextManagerExample2.counter += 100
externalCounter3 += 2
contextManagerExample3.counter += 200
autoTester.check ('ctx3', contextManagerExample3.counter, externalCounter3)
externalCounter2 += 2
contextManagerExample2.counter += 200
autoTester.check ('ctx2', contextManagerExample2.counter, externalCounter2)
try:
externalCounter4 = 0
with ContextManagerExample () as contextManagerExample4:
externalCounter4 += 1
contextManagerExample4.counter += 100
externalCounter5 = 0
with ContextManagerExample () as contextManagerExample5:
externalCounter5 += 1
contextManagerExample5.counter += 100
raise Exception ()
externalCounter5 += 2
contextManagerExample5.counter += 200
externalCounter4 += 2
contextManagerExample4.counter += 200
except Exception as exception:
autoTester.check ('ctx6', exception)
finally:
autoTester.check ('ctx5', contextManagerExample5.counter, externalCounter5)
autoTester.check ('ctx4', contextManagerExample4.counter, externalCounter4)
# Multiple context managers in one clause
# $$$ The new parsers seems to treat them more like separate context managers.
# $$$ Or maybe it's a command line switch.
iterationCount = 0
with ContextManagerExample () as contextManagerExample5, ContextManagerExample () as contextManagerExample6:
iterationCount += 1
autoTester.check ('ctx7', iterationCount, contextManagerExample5.counter, contextManagerExample6.counter)
iterationCount = 0
with ContextManagerExample (), ContextManagerExample (), ContextManagerExample (), \
ContextManagerExample (), ContextManagerExample ():
iterationCount += 1
autoTester.check ('ctx8', iterationCount)
”…”�”}”(hhhj ubah}”(h ]”h"]”h$]”h&]”h(]”Œsource”Œ~/home/jac/active/geatec/transcrypt/Transcrypt/transcrypt/development/automated_tests/transcrypt/control_structures/__init__.py”hŒh�hމh�}”h‘Ksuh*hzhh+hKKhjú ubeh}”(h ]”Œid10”ah"]”h–ah$]”h&]”h(]”Œ
literal_block”ˆuh*hehjé hhhhhNubeh}”(h ]”ŒBcontrol-structures-for-else-while-else-if-elif-else-break-continue”ah"]”h$]”ŒOcontrol structures: for...else, while...else, if...elif...else, break, continue”ah&]”h(]”uh*h
hhhhhh+hKIubh)�”}”(hhh]”(h)�”}”(hŒ'Data classes: Avoiding boilerplate code”h]”hŒ'Data classes: Avoiding boilerplate code”…”�”}”(hj1 hj/ hhhNhNubah}”(h ]”h"]”h$]”h&]”h(]”uh*hhj, hhhh+hKPubhf)�”}”(hhh]”(hk)�”}”(hŒTestlet: data_classes”h]”hŒTestlet: data_classes”…”�”}”(hjB hj@ ubah}”(h ]”h"]”h$]”h&]”h(]”uh*hjhh+hKRhj= ubh{)�”}”(hX« from dataclasses import dataclass
from typing import ClassVar
def getQ ():
return 1002
@dataclass
class A:
m = 101010
n: int = 202020
@dataclass
class B (A):
p: int = 1001
q: int = 1002
@dataclass (order = True)
class C (B):
@dataclass
class CC (B):
k: int = 40
l: float = 55.5
j = 60
x: ClassVar = 10
y: int = 20
yy: int = 22
z: int = 30
zz: int = 33
t: ClassVar = 40
g = 100000
h = 100001
i = 100002
def getV (self):
return 3
def setV (self, value):
pass
v = property (getV, setV)
def getW (self):
return 4
def setW (self, value):
pass
w: int = property (getW, setW)
def f (self, p, autoTester):
self.a = p
self.b = 2000
autoTester.check (self.x, self.y, self.a)
return f'something(a: {self.a}, b: {self.b})'
@dataclass (order = True)
class D:
_p: int = 3
def setP (self, value):
pass
#self._p = value
def getP (self):
return 20
#return self._p
p: int = property (getP, setP)
def run (autoTester):
c = C (y = 200, zz = 330)
cc = C (y = 10200)
c.f (123, autoTester)
c.t = 400
cc.f (456, autoTester)
cc.t = 4000
for obj in c, cc:
autoTester.check (obj.x, obj.y, obj.yy, obj.z, obj.zz, obj.t, obj.a, obj.b)
autoTester.check (repr (c))
autoTester.check (repr (cc))
#__pragma__ ('opov')
autoTester.check (c == cc)
autoTester.check (c != cc)
autoTester.check (c < cc)
autoTester.check (c > cc) #
autoTester.check (c <= cc) #
autoTester.check (c >= cc)
autoTester.check (c == c)
autoTester.check (c != c)
autoTester.check (c < c)
autoTester.check (c > c)
autoTester.check (c <= c)
autoTester.check (c >= c)
d3 = D ()
d1 = D ()
d2 = D ()
autoTester.check (repr (d1))
autoTester.check (d3, d1, d3 > d1)
autoTester.check (d2, d1, d2 > d1)
autoTester.check (d3, d2, d3 > d2)
ccc = C.CC ()
autoTester.check (ccc.n, ccc.p, ccc.q, ccc.k, ccc.l)
”h]”hX« from dataclasses import dataclass
from typing import ClassVar
def getQ ():
return 1002
@dataclass
class A:
m = 101010
n: int = 202020
@dataclass
class B (A):
p: int = 1001
q: int = 1002
@dataclass (order = True)
class C (B):
@dataclass
class CC (B):
k: int = 40
l: float = 55.5
j = 60
x: ClassVar = 10
y: int = 20
yy: int = 22
z: int = 30
zz: int = 33
t: ClassVar = 40
g = 100000
h = 100001
i = 100002
def getV (self):
return 3
def setV (self, value):
pass
v = property (getV, setV)
def getW (self):
return 4
def setW (self, value):
pass
w: int = property (getW, setW)
def f (self, p, autoTester):
self.a = p
self.b = 2000
autoTester.check (self.x, self.y, self.a)
return f'something(a: {self.a}, b: {self.b})'
@dataclass (order = True)
class D:
_p: int = 3
def setP (self, value):
pass
#self._p = value
def getP (self):
return 20
#return self._p
p: int = property (getP, setP)
def run (autoTester):
c = C (y = 200, zz = 330)
cc = C (y = 10200)
c.f (123, autoTester)
c.t = 400
cc.f (456, autoTester)
cc.t = 4000
for obj in c, cc:
autoTester.check (obj.x, obj.y, obj.yy, obj.z, obj.zz, obj.t, obj.a, obj.b)
autoTester.check (repr (c))
autoTester.check (repr (cc))
#__pragma__ ('opov')
autoTester.check (c == cc)
autoTester.check (c != cc)
autoTester.check (c < cc)
autoTester.check (c > cc) #
autoTester.check (c <= cc) #
autoTester.check (c >= cc)
autoTester.check (c == c)
autoTester.check (c != c)
autoTester.check (c < c)
autoTester.check (c > c)
autoTester.check (c <= c)
autoTester.check (c >= c)
d3 = D ()
d1 = D ()
d2 = D ()
autoTester.check (repr (d1))
autoTester.check (d3, d1, d3 > d1)
autoTester.check (d2, d1, d2 > d1)
autoTester.check (d3, d2, d3 > d2)
ccc = C.CC ()
autoTester.check (ccc.n, ccc.p, ccc.q, ccc.k, ccc.l)
”…”�”}”(hhhjN ubah}”(h ]”h"]”h$]”h&]”h(]”Œsource”Œx/home/jac/active/geatec/transcrypt/Transcrypt/transcrypt/development/automated_tests/transcrypt/data_classes/__init__.py”hŒh�hމh�}”h‘Ksuh*hzhh+hKRhj= ubeh}”(h ]”Œid11”ah"]”h–ah$]”h&]”h(]”Œ
literal_block”ˆuh*hehj, hhhhhNubeh}”(h ]”Œ&data-classes-avoiding-boilerplate-code”ah"]”h$]”Œ'data classes: avoiding boilerplate code”ah&]”h(]”uh*h
hhhhhh+hKPubh)�”}”(hhh]”(h)�”}”(hŒ'Data structures: tuple, list, dict, set”h]”hŒ'Data structures: tuple, list, dict, set”…”�”}”(hjt hjr hhhNhNubah}”(h ]”h"]”h$]”h&]”h(]”uh*hhjo hhhh+hKWubhf)�”}”(hhh]”(hk)�”}”(hŒTestlet: data_structures”h]”hŒTestlet: data_structures”…”�”}”(hj… hjƒ ubah}”(h ]”h"]”h$]”h&]”h(]”uh*hjhh+hKYhj€ ubh{)�”}”(hX def run (autoTester):
aList = [1, 2, 3, 'moon', 'stars']
autoTester.check (aList)
aList.insert (3, 'sun')
autoTester.check (aList)
autoTester.check (aList [2:4:1])
autoTester.check (aList [:])
autoTester.check (aList [2:])
autoTester.check (len (aList))
aList.append ('milkyway')
autoTester.check (aList)
aList.extend (['m1', 'm31'])
autoTester.check (aList)
anotherList = list (('a', 'b', 'c'))
autoTester.check (anotherList)
autoTester.check ('b' in anotherList)
autoTester.check ('d' in anotherList)
aDict = {1: 'plant', 'animal': 2}
autoTester.check (aDict)
autoTester.check (aDict [1], aDict ['animal'])
def p ():
return 3
q = 4
autoTester.check ({p (): 'three', q: 'four'})
aTuple = (1, 2, 3, 4, 5)
autoTester.check(aTuple)
autoTester.check (len (aTuple))
anotherTuple = (1,)
autoTester.check (anotherTuple)
aSet = {1, 2, 2, 3}
autoTester.check (aSet)
autoTester.check (len (aSet))
autoTester.check (2 in aSet)
autoTester.check (4 in aSet)
aSet.clear ()
autoTester.check (aSet)
anotherSet = set ((4, 5, 5, 6))
autoTester.check (anotherSet)
emptySet = set ()
autoTester.check (emptySet)
autoTester.check (len (emptySet))
aString = 'c_cis_d_dis_e_f_fis_g_gis_a_ais_b_c'
autoTester.check ('cis' in aString)
autoTester.check ('g' in aString)
autoTester.check ('bes' in aString)
autoTester.check ('z' in aString)
”h]”hX def run (autoTester):
aList = [1, 2, 3, 'moon', 'stars']
autoTester.check (aList)
aList.insert (3, 'sun')
autoTester.check (aList)
autoTester.check (aList [2:4:1])
autoTester.check (aList [:])
autoTester.check (aList [2:])
autoTester.check (len (aList))
aList.append ('milkyway')
autoTester.check (aList)
aList.extend (['m1', 'm31'])
autoTester.check (aList)
anotherList = list (('a', 'b', 'c'))
autoTester.check (anotherList)
autoTester.check ('b' in anotherList)
autoTester.check ('d' in anotherList)
aDict = {1: 'plant', 'animal': 2}
autoTester.check (aDict)
autoTester.check (aDict [1], aDict ['animal'])
def p ():
return 3
q = 4
autoTester.check ({p (): 'three', q: 'four'})
aTuple = (1, 2, 3, 4, 5)
autoTester.check(aTuple)
autoTester.check (len (aTuple))
anotherTuple = (1,)
autoTester.check (anotherTuple)
aSet = {1, 2, 2, 3}
autoTester.check (aSet)
autoTester.check (len (aSet))
autoTester.check (2 in aSet)
autoTester.check (4 in aSet)
aSet.clear ()
autoTester.check (aSet)
anotherSet = set ((4, 5, 5, 6))
autoTester.check (anotherSet)
emptySet = set ()
autoTester.check (emptySet)
autoTester.check (len (emptySet))
aString = 'c_cis_d_dis_e_f_fis_g_gis_a_ais_b_c'
autoTester.check ('cis' in aString)
autoTester.check ('g' in aString)
autoTester.check ('bes' in aString)
autoTester.check ('z' in aString)
”…”�”•+ }”(hhhj‘ ubah}”(h ]”h"]”h$]”h&]”h(]”Œsource”Œ{/home/jac/active/geatec/transcrypt/Transcrypt/transcrypt/development/automated_tests/transcrypt/data_structures/__init__.py”hŒh�hމh�}”h‘Ksuh*hzhh+hKYhj€ ubeh}”(h ]”Œid12”ah"]”h–ah$]”h&]”h(]”Œ
literal_block”ˆuh*hehjo hhhhhNubeh}”(h ]”Œ#data-structures-tuple-list-dict-set”ah"]”h$]”Œ'data structures: tuple, list, dict, set”ah&]”h(]”uh*h
hhhhhh+hKWubh)�”}”(hhh]”(h)�”}”(hŒ;Decorators: function and class, with and without parameters”h]”hŒ;Decorators: function and class, with and without parameters”…”�”}”(hj· hjµ hhhNhNubah}”(h ]”h"]”h$]”h&]”h(]”uh*hhj² hhhh+hK^ubh-)�”}”(hXu Transcrypt supports decorators on methods and classes. A decorator itself can be a function or an object with an overloaded __call__ operator. Parameterized decorator factories are also supported. All flavours of properties can be used directly or through decorator syntax. Extensive use of properties is demonstrated in the :ref:`properties testlet `.”h]”(hXE Transcrypt supports decorators on methods and classes. A decorator itself can be a function or an object with an overloaded __call__ operator. Parameterized decorator factories are also supported. All flavours of properties can be used directly or through decorator syntax. Extensive use of properties is demonstrated in the ”…”�”}”(hXE Transcrypt supports decorators on methods and classes. A decorator itself can be a function or an object with an overloaded __call__ operator. Parameterized decorator factories are also supported. All flavours of properties can be used directly or through decorator syntax. Extensive use of properties is demonstrated in the ”hjà hhhNhNubh Œpending_xref”“”)�”}”(hŒ/:ref:`properties testlet `”h]”h Œinline”“”)�”}”(hjÐ h]”hŒproperties testlet”…”�”}”(hhhjÔ ubah}”(h ]”h"]”(Œxref”Œstd”Œstd-ref”eh$]”h&]”h(]”uh*jÒ hjÎ ubah}”(h ]”h"]”h$]”h&]”h(]”Œrefdoc”Œsupported_constructs”Œ refdomain”jß Œreftype”Œref”Œrefexplicit”ˆŒrefwarn”ˆŒ reftarget”Œautotest_properties”uh*jÌ hh+hK`hjà ubhŒ.”…”�”}”(hŒ.”hjà hhhNhNubeh}”(h ]”h"]”h$]”h&]”h(]”uh*h,hh+hK`hj² hhubhf)�”}”(hhh]”(hk)�”}”(hŒTestlet: decorators”h]”hŒTestlet: decorators”…”�”}”(hj hj ubah}”(h ]”h"]”h$]”h&]”h(]”uh*hjhh+hKbhjþ ubh{)�”}”(hX”
from org.transcrypt.stubs.browser import __pragma__
def run (autoTester):
def repeat3 (bareFunc):
__pragma__ ('kwargs')
def innerFunc (*args, **kwargs):
autoTester.check ('BEGIN repeat3')
for i in range (3):
bareFunc (*args, **kwargs)
autoTester.check ('END repeat3')
__pragma__ ('nokwargs')
return innerFunc
def repeatN (n):
def repeat (bareFunc):
__pragma__ ('kwargs')
def innerFunc (*args, **kwargs):
autoTester.check ('BEGIN repeatN ({})'.format (n))
for i in range (n):
bareFunc (*args, **kwargs)
autoTester.check ('END repeatN ({})'.format (n))
__pragma__ ('nokwargs')
return innerFunc
return repeat
class Repeater:
def __init__ (self, n):
self.n = n
def __call__ (self, bareFunc):
__pragma__ ('kwargs')
def innerFunc (*args, **kwargs):
autoTester.check ('BEGIN repeat3')
for i in range (self.n):
bareFunc (*args, **kwargs)
autoTester.check ('END repeat3')
__pragma__ ('nokwargs')
return innerFunc
@repeatN (4)
@repeat3
def funcNoArg ():
autoTester.check ('spam')
funcNoArg ()
autoTester.check ()
__pragma__ ('kwargs')
@repeat3
@repeatN (2)
def funcArg (a):
autoTester.check ('eggs', a)
__pragma__ ('nokwargs')
funcArg (3)
autoTester.check ()
funcArg (a = 4)
autoTester.check ()
__pragma__ ('opov')
@Repeater (3)
def funcNoArg2 ():
autoTester.check ('toast')
__pragma__ ('noopov')
funcNoArg2 ()
autoTester.check ()
__pragma__ ('opov')
__pragma__ ('kwargs')
@Repeater (5)
def funcArg2 (a):
autoTester.check ('jam', a)
__pragma__ ('nokwargs')
__pragma__ ('noopov')
funcArg2 (3)
autoTester.check ()
funcArg2 (a = 4)
autoTester.check ()
def next (bareFunc):
def innerFunc (value):
return bareFunc (value + 1)
return innerFunc
@next
class Number:
def __init__ (self, value):
self.value = value
autoTester.check ('two', Number (1) .value)
class Test:
@classmethod
def f (cls, x, y):
autoTester.check (cls.__name__, x, y)
def g (self, x, y):
autoTester.check (self.__class__.__name__, x, y)
test = Test ()
test.f (1, 2)
test.g (3, 4)
”h]”hX”
from org.transcrypt.stubs.browser import __pragma__
def run (autoTester):
def repeat3 (bareFunc):
__pragma__ ('kwargs')
def innerFunc (*args, **kwargs):
autoTester.check ('BEGIN repeat3')
for i in range (3):
bareFunc (*args, **kwargs)
autoTester.check ('END repeat3')
__pragma__ ('nokwargs')
return innerFunc
def repeatN (n):
def repeat (bareFunc):
__pragma__ ('kwargs')
def innerFunc (*args, **kwargs):
autoTester.check ('BEGIN repeatN ({})'.format (n))
for i in range (n):
bareFunc (*args, **kwargs)
autoTester.check ('END repeatN ({})'.format (n))
__pragma__ ('nokwargs')
return innerFunc
return repeat
class Repeater:
def __init__ (self, n):
self.n = n
def __call__ (self, bareFunc):
__pragma__ ('kwargs')
def innerFunc (*args, **kwargs):
autoTester.check ('BEGIN repeat3')
for i in range (self.n):
bareFunc (*args, **kwargs)
autoTester.check ('END repeat3')
__pragma__ ('nokwargs')
return innerFunc
@repeatN (4)
@repeat3
def funcNoArg ():
autoTester.check ('spam')
funcNoArg ()
autoTester.check ()
__pragma__ ('kwargs')
@repeat3
@repeatN (2)
def funcArg (a):
autoTester.check ('eggs', a)
__pragma__ ('nokwargs')
funcArg (3)
autoTester.check ()
funcArg (a = 4)
autoTester.check ()
__pragma__ ('opov')
@Repeater (3)
def funcNoArg2 ():
autoTester.check ('toast')
__pragma__ ('noopov')
funcNoArg2 ()
autoTester.check ()
__pragma__ ('opov')
__pragma__ ('kwargs')
@Repeater (5)
def funcArg2 (a):
autoTester.check ('jam', a)
__pragma__ ('nokwargs')
__pragma__ ('noopov')
funcArg2 (3)
autoTester.check ()
funcArg2 (a = 4)
autoTester.check ()
def next (bareFunc):
def innerFunc (value):
return bareFunc (value + 1)
return innerFunc
@next
class Number:
def __init__ (self, value):
self.value = value
autoTester.check ('two', Number (1) .value)
class Test:
@classmethod
def f (cls, x, y):
autoTester.check (cls.__name__, x, y)
def g (self, x, y):
autoTester.check (self.__class__.__name__, x, y)
test = Test ()
test.f (1, 2)
test.g (3, 4)
”…”�”}”(hhhj ubah}”(h ]”h"]”h$]”h&]”h(]”Œsource”Œv/home/jac/active/geatec/transcrypt/Transcrypt/transcrypt/development/automated_tests/transcrypt/decorators/__init__.py”hŒh�hމh�}”h‘Ksuh*hzhh+hKbhjþ ubeh}”(h ]”Œid13”ah"]”h–ah$]”h&]”h(]”Œ
literal_block”ˆuh*hehj² hhhhhNubeh}”(h ]”Œ9decorators-function-and-class-with-and-without-parameters”ah"]”h$]”Œ;decorators: function and class, with and without parameters”ah&]”h(]”uh*h
hhhhhh+hK^ubh)�”}”(hhh]”(h)�”}”(hŒDict comprehensions”h]”hŒDict comprehensions”…”�”}”(hj5 hj3 hhhNhNubah}”(h ]”h"]”h$]”h&]”h(]”uh*hhj0 hhhh+hKgubhf)�”}”(hhh]”(hk)�”}”(hŒTestlet: dict_comprehensions”h]”hŒTestlet: dict_comprehensions”…”�”}”(hjF hjD ubah}”(h ]”h"]”h$]”h&]”h(]”uh*hjhh+hKihjA ubh{)�”}”(hX` from org.transcrypt.stubs.browser import __pragma__
__pragma__ ('iconv') # Convert dict to key list without using keys () method
def run (autoTester):
original = {'Isaac': 'Newton', 'Albert': 'Einstein', 'Paul': 'Dirac'}
autoTester.check (original)
inverted = {original [key]: key for key in original}
autoTester.check (inverted)
”h]”hX` from org.transcrypt.stubs.browser import __pragma__
__pragma__ ('iconv') # Convert dict to key list without using keys () method
def run (autoTester):
original = {'Isaac': 'Newton', 'Albert': 'Einstein', 'Paul': 'Dirac'}
autoTester.check (original)
inverted = {original [key]: key for key in original}
autoTester.check (inverted)
”…”�”}”(hhhjR ubah}”(h ]”h"]”h$]”h&]”h(]”Œsource”Œ/home/jac/active/geatec/transcrypt/Transcrypt/transcrypt/development/automated_tests/transcrypt/dict_comprehensions/__init__.py”hŒh�hމh�}”h‘Ksuh*hzhh+hKihjA ubeh}”(h ]”Œid14”ah"]”h–ah$]”h&]”h(]”Œ
literal_block”ˆuh*hehj0 hhhhhNubeh}”(h ]”Œdict-comprehensions”ah"]”h$]”Œdict comprehensions”ah&]”h(]”uh*h
hhhhhh+hKgubh)�”}”(hhh]”(h)�”}”(hŒDictionaries: dict revisited”h]”hŒDictionaries: dict revisited”…”�”}”(hjx hjv hhhNhNubah}”(h ]”h"]”h$]”h&]”h(]”uh*hhjs hhhh+hKnubhf)�”}”(hhh]”(hk)�”}”(hŒTestlet: dictionaries”h]”hŒTestlet: dictionaries”…”�”}”(hj‰ hj‡ ubah}”(h ]”h"]”h$]”h&]”h(]”uh*hjhh+hKphj„ ubh{)�”}”(hX™
from org.transcrypt.stubs.browser import __pragma__
__pragma__ ('iconv')
# Dictionaries are translated to JavaScript objects,
# to achieve JSON-compatible syntax for JavaScript library object initialisation.
# Keys that may denote a number are interpreted as such in Transcrypt.
# All other keys are interpreted as strings.
def run (autoTester):
tel = {'guido': 4127, 'jack': 4098}
autoTester.check (len (tel))
tel ['sape'] = 4139
autoTester.check (tel)
autoTester.check (tel ['jack'])
del tel ['sape']
tel ['irv'] = 4127
autoTester.check (tel)
autoTester.check (sorted (list (tel.keys ())), False)
autoTester.check (sorted (tel.keys ()))
autoTester.check ('guido' in tel)
autoTester.check ('jack' not in tel)
autoTester.check (dict ([('guido', 4127), ('jack', 4098), ('sape', 4139)]))
autoTester.check (
autoTester.expectException( lambda: dict(1) )
)
autoTester.check (
autoTester.expectException( lambda: dict(134.34) )
)
autoTester.check (
autoTester.expectException( lambda: dict('asdf') )
)
autoTester.check (
autoTester.expectException( lambda: dict(['1234', 1]) )
)
autoTester.check( dict ([]))
autoTester.check (dict ({}))
autoTester.check (dict ({'asdf': 1, 'qwer': 2}) )
# check dict copy, Issue # 221
b = {'a' : 2.01, 'b': -3.3}
d = dict (b)
autoTester.check (d)
b = {'a' : 2, 'b': [1,2,3]}
d = dict (b)
autoTester.check (d)
b = {'a' : None, 'b': set([1,2,3])}
d = dict (b)
autoTester.check (d)
b = {'a' : {'c': 2}, 'b': (1,2)}
d = dict (b)
autoTester.check (d)
autoTester.check (d['a']['c'])
autoTester.check (d.get('a').get('c'))
autoTester.check (b.get('a').get('c'))
d['a']['c'] = 3
autoTester.check (d.get('a').get('c'))
autoTester.check (b.get('a').get('c'))
knights = {'robin': 'the brave', 'gallahad': 'the pure'}
for k, v in sorted (knights.items ()):
autoTester.check (k, v)
if 'gallahad' in knights:
autoTester.check ('gallahad is a knight')
for k in sorted (knights):
autoTester.check (k)
knight = {'rudolph': 'the righteous'}
for k in knight: # Autotest automatic conversion with one knight, since sort order of dict undefined
autoTester.check (k)
tel = {'guido': 123}
tel.update({'edsger': 42})
autoTester.check (tel.setdefault ('linus', 456))
autoTester.check (tel ['linus'])
autoTester.check (tel.setdefault ('guido', 789))
autoTester.check (tel.pop ('guido', 1))
autoTester.check (tel.pop ('guido', 1))
autoTester.check (tel.pop ('edsger', 2))
autoTester.check (tel.pop ('foo', 'bar'))
autoTester.check (tel.pop ('foo', None))
# Check compound keys (issue 281)
d = {}
d ['a'] = 3777
d [(1, 2)] = 4777
autoTester.check (d ['a'], d [(1, 2)])
__pragma__ ('opov')
d = {}
d ['a'] = 3777
d [(1, 2)] = 4777
autoTester.check (d ['a'], d [(1, 2)])
__pragma__ ('noopov')
# Check exceptions
knights = {'robin': 'the brave', 'gallahad': 'the pure'}
autoTester.check (
autoTester.expectException ( lambda: knights.pop("batman") )
)
autoTester.check (
autoTester.expectException ( lambda: knights.pop("batman", None) )
)
autoTester.check (
autoTester.expectException ( lambda: knights.pop("batman", "the gullible") )
)
”h]”hX™
from org.transcrypt.stubs.browser import __pragma__
__pragma__ ('iconv')
# Dictionaries are translated to JavaScript objects,
# to achieve JSON-compatible syntax for JavaScript library object initialisation.
# Keys that may denote a number are interpreted as such in Transcrypt.
# All other keys are interpreted as strings.
def run (autoTester):
tel = {'guido': 4127, 'jack': 4098}
autoTester.check (len (tel))
tel ['sape'] = 4139
autoTester.check (tel)
autoTester.check (tel ['jack'])
del tel ['sape']
tel ['irv'] = 4127
autoTester.check (tel)
autoTester.check (sorted (list (tel.keys ())), False)
autoTester.check (sorted (tel.keys ()))
autoTester.check ('guido' in tel)
autoTester.check ('jack' not in tel)
autoTester.check (dict ([('guido', 4127), ('jack', 4098), ('sape', 4139)]))
autoTester.check (
autoTester.expectException( lambda: dict(1) )
)
autoTester.check (
autoTester.expectException( lambda: dict(134.34) )
)
autoTester.check (
autoTester.expectException( lambda: dict('asdf') )
)
autoTester.check (
autoTester.expectException( lambda: dict(['1234', 1]) )
)
autoTester.check( dict ([]))
autoTester.check (dict ({}))
autoTester.check (dict ({'asdf': 1, 'qwer': 2}) )
# check dict copy, Issue # 221
b = {'a' : 2.01, 'b': -3.3}
d = dict (b)
autoTester.check (d)
b = {'a' : 2, 'b': [1,2,3]}
d = dict (b)
autoTester.check (d)
b = {'a' : None, 'b': set([1,2,3])}
d = dict (b)
autoTester.check (d)
b = {'a' : {'c': 2}, 'b': (1,2)}
d = dict (b)
autoTester.check (d)
autoTester.check (d['a']['c'])
autoTester.check (d.get('a').get('c'))
autoTester.check (b.get('a').get('c'))
d['a']['c'] = 3
autoTester.check (d.get('a').get('c'))
autoTester.check (b.get('a').get('c'))
knights = {'robin': 'the brave', 'gallahad': 'the pure'}
for k, v in sorted (knights.items ()):
autoTester.check (k, v)
if 'gallahad' in knights:
autoTester.check ('gallahad is a knight')
for k in sorted (knights):
autoTester.check (k)
knight = {'rudolph': 'the righteous'}
for k in knight: # Autotest automatic conversion with one knight, since sort order of dict undefined
autoTester.check (k)
tel = {'guido': 123}
tel.update({'edsger': 42})
autoTester.check (tel.setdefault ('linus', 456))
autoTester.check (tel ['linus'])
autoTester.check (tel.setdefault ('guido', 789))
autoTester.check (tel.pop ('guido', 1))
autoTester.check (tel.pop ('guido', 1))
autoTester.check (tel.pop ('edsger', 2))
autoTester.check (tel.pop ('foo', 'bar'))
autoTester.check (tel.pop ('foo', None))
# Check compound keys (issue 281)
d = {}
d ['a'] = 3777
d [(1, 2)] = 4777
autoTester.check (d ['a'], d [(1, 2)])
__pragma__ ('opov')
d = {}
d ['a'] = 3777
d [(1, 2)] = 4777
autoTester.check (d ['a'], d [(1, 2)])
__pragma__ ('noopov')
# Check exceptions
knights = {'robin': 'the brave', 'gallahad': 'the pure'}
autoTester.check (
autoTester.expectException ( lambda: knights.pop("batman") )
)
autoTester.check (
autoTester.expectException ( lambda: knights.pop("batman", None) )
)
autoTester.check (
autoTester.expectException ( lambda: knights.pop("batman", "the gullible") )
)
”…”�”}”(hhhj• ubah}”(h ]”h"]”h$]”h&]”h(]”Œsource”Œx/home/jac/active/geatec/transcrypt/Transcrypt/transcrypt/development/automated_tests/transcrypt/dictionaries/__init__.py”hŒh�hމh�}”h‘Ksuh*hzhh+hKphj„ ubeh}”(h ]”Œid15”ah"]”h–ah$]”h&]”h(]”Œ
literal_block”ˆuh*hehjs hhhhhNubhœ)�”}”(hŒ.. _autotest_docstrings:”h]”h}”(h ]”h"]”h$]”h&]”h(]”h§Œautotest-docstrings”uh*h›hKthjs hhhh+ubeh}”(h ]”Œdictionaries-dict-revisited”ah"]”h$]”Œdictionaries: dict revisited”ah&]”h(]”uh*h
hhhhhh+hKnubh)�”}”(hhh]”(h)�”}”(hŒDiverse issues”h]”hŒDiverse issues”…”�”}”(hjÆ hjÄ hhhNhNubah}”(h ]”h"]”h$]”h&]”h(]”uh*hhjÁ hhhh+hKwubhf)�”}”(hhh]”(hk)�”}”(hŒTestlet: div_issues”h]”hŒTestlet: div_issues”…”�”}”(hj× hjÕ ubah}”(h ]”h"]”h$]”h&]”h(]”uh*hjhh+hKyhjÒ ubh{)�”}”(hX'F from org.transcrypt.stubs.browser import __pragma__, __new__, __envir__, __symbols__
from div_issues.issue55 import * # Names not exported from package's __init__.py, no output, only compilation check
from div_issues.issue387 import run387 # Support __module__ and __qualname__ for introspection (only __module__ done and
# __name__ set to '__main__ for main module'
from div_issues.issue559 import run559 # Imported names not reexported form the __init__.py of a module
import re
def run (autoTester):
autoTester.check ('Issue 24') # Non keyword switch generates javascript SyntaxError
switch = False
autoTester.check (switch)
autoTester.check ('Issue 27') # Python list.index () not translated correctly
autoTester.check (['zero', 'one', 'two', 'three', 'four'] .index ('three'))
autoTester.check ('Issue 36') # Bug in compiling lambda default argument values
# Workaround for Python closures capturing variables rather than values
# An extra enclosing scope is created to remember the value of the variable
results = []
for i in range (10):
# results.append (lambda: i) # Works nowhere
# results.append (lambda j = i: j) # Works only in Python
results.append ((lambda j: lambda: j) (i)) # Works in Python and Transcrypt
autoTester.check ([result () for result in results])
autoTester.check ('Issue 37') # Python integer division not translated correctly
autoTester.check (15 // 7)
autoTester.check ('Issue 40') # Python parentheses dropped during translation
autoTester.check (65 / (5 * 2))
autoTester.check ('Issue 50') # Wrong answer with parentheses moved during translation
autoTester.check ((240 + 30 - 1) // 30 * 30)
autoTester.check ('Issue 51') # Wrong answer with set() compare
a = 1
b = 1
autoTester.check (a, b, {a, b} == {1, 2})
autoTester.check ('Issue 52') # Non keyword 'default' generates javascript SyntaxError
switch, case, default = 'switch', 'case', 'default'
autoTester.check (switch, case, default)
autoTester.check ('Issue 54') # Type dict missing clear(), setdefault()
aDict = {1: 11, 2: 22, 3: 33}
autoTester.check (aDict)
aDict.clear ()
autoTester.check (aDict)
autoTester.check ('Issue 60') # Python bool() not translated
three = 3
one = three & 1
seven = three | 4
eight = one << 3
four = eight >> 1
aTrue = bool (three & one)
aFalse = bool (three & four)
autoTester.check (3, three, 1, one, 7, seven, 8, eight, 4, four, True, aTrue, False, aFalse)
autoTester.check ('Issue 65') # Adding two lists with + not supported
__pragma__ ('opov')
aList = [4, 5, 6]
autoTester.check ([1, 2, 3,] + aList + [4, 5, 6])
autoTester.check (3 * [1, 2, 3])
autoTester.check ([1, 2, 3] * 3)
aString = 'Crocodile'
autoTester.check ('Tiger' + aString + 'Elephant')
autoTester.check (3 * aString)
autoTester.check (aString * 3)
__pragma__ ('noopov')
autoTester.check ('Issue 76') # Python //= not translated correctly
initially17 = 17
autoTester.check (initially17)
initially17 //= 2
autoTester.check (initially17)
initially17 //= 2
autoTester.check (initially17)
autoTester.check ('Issue 112') # When using -e6, iterating TypedArrays or other non-list Iterables doesn't work
try:
if __envir__.executor_name == __envir__.transpiler_name: # CPython doesn't know Int8Array
x = __new__ (Int8Array (2))
else:
x = [None, None]
x [0] = 3
x [1] = 2
for i in x:
autoTester.check (i)
y = 3
for j in y:
autoTester.check (j)
except: # No 'Exception' can be used behind this, since this is a JavaScript exception, and no subclass of Exception. ??? How desirable is this behaviour?
pass
# autoTester.check ('Detected iterating over non-iterable') # Minifier masks this exception, so we'll have to pass
autoTester.check ('Issue 122') # Problem with yield (or rather with slicing beyond list end)
def chunks (aList, chunkLength):
for index in range (0, len (aList), chunkLength):
yield aList [index : index + chunkLength]
for chunk in chunks ([chr (index + 97) for index in range (26)], 10):
autoTester.check (chunk)
autoTester.check ('Issue 123') # Python % shouldn't behave like JS %
autoTester.check (10 % 3, 10 % -3, -10 % 3, -10 % -3, 10 % 10, 10 % -10, -10 % 10, -10 % -10)
autoTester.check ('Issue 125') # Strings not iterable
abc = 'abc'
for index in abc:
autoTester.check (abc)
autoTester.check ('Issue 127') # Can't use the key 'keys' in a dict
autoTester.check ({"include_docs": "true", "keys": ["key1", "key2"], "limit": 50})
autoTester.check ('Issue 134') # Operator %= translated incorrectly
x0, x1, x2, x3, x4, x5 = 5, 12, -5, -5, 0, 0
x0 %= 10; x1 %= 5; x2 %= 2; x3 %= -3; x4 %= 1; x5 %= -1000
autoTester.check (x0, x1, x2, x3, x4)
autoTester.check ('Issue 136') # Method dict.get(key[, default]) not implemented
aDict = {'a': 'ape', 'b': 'banana'}
autoTester.check (aDict.get ('a', 'noApe'), aDict.get ('b'), aDict.get ('c', 'noCarot'), aDict.get ('d'))
autoTester.check ('Issue 144')
__pragma__('opov')
aList = [x for x in [1, 2, 3]]
autoTester.check (aList)
__pragma__('noopov')
autoTester.check ('
Issue 145
') # List sorting incorrect in case of multiple columns
class SortTest:
def __init__ (self):
self.alphabet = 'abcdefghijklmnopqrstuvwxyz'
self.nChars = 10
self.nCols = 10
self.nRows = 30
self.pseudoRandom = 0
def randomWord ():
word = ''
for iChar in range (self.nChars):
self.pseudoRandom = (81212 * self.pseudoRandom + 28411) % 134456
# self.pseudoRandom = (1234 * self.pseudoRandom + 57) % 137 # Deliberately short period
word += self.alphabet [self.pseudoRandom % 26]
return word
self.rows = [[randomWord () for iCol in range (self.nCols)] for iRow in range (self.nRows)]
def sort (self):
for iCol in reversed (range (self.nCols)):
self.rows.sort (key = lambda row: row [iCol])
sortTest = SortTest ()
autoTester.check ('
Unsorted:
')
for row in sortTest.rows:
autoTester.check ('{}
'.format (','.join ([word for word in row])))
sortTest.sort ()
autoTester.check ('
Sorted:
')
for row in sortTest.rows:
autoTester.check ('{}
'.format (','.join ([word for word in row])))
autoTester.check ('
Issue 148
') # Allow key a.o. key 'items' in dict
aDict = {
'items': [4, 5, 6]
}
for aKey, aValue in aDict.items ():
autoTester.check ('{}: {}'.format (aKey, aValue))
autoTester.check ('
Issue 169
') # Add support for float('inf') and float('-inf')
autoTester.check (int (1 / float ('inf')), int (1 / float ('-inf')))
autoTester.check ('
Issue 178
') # List Comprehensions / Operator Precedence Bug
bitmaps = [
(2 , ''),
(4 , ''),
(8, 'i'),
(16, 'm'),
(32, 'y'),
(64, 'u'),
(128, 'g')
]
for flags in (122, 233, 11, 55, 79, 201, 23, 111, 200, 100, 50, 25, 12, 6):
autoTester.check (''.join ([x [1] for x in bitmaps if (x [0] & flags) > 0]))
def issue256 ():
autoTester.check ('Issue 256')
class C:
def __init__ (self, value):
self.value = value
def f1 (value): # Generate parens after return
return (C (value) .value or 'second') .capitalize () == 'First'
def f2 (value): # Generate parens after return
return (C (value) .value or 'second') .capitalize () == 'Second'
def f3 (value): # Generate NO parens after return
return C (value) .value or 'second'
def f4 (value): # Generate NO parens after return
return (C (value) .value or 'second')
autoTester.check (f1 ('first'))
autoTester.check (f1 (''))
autoTester.check (f2 ('first'))
autoTester.check (f2 (''))
autoTester.check (f3 ('first'))
autoTester.check (f4 (''))
issue256 ()
autoTester.check ('Issue 274')
a = 3
del a
autoTester.check ('Still alive')
autoTester.check ('Issue 276') # Partial, other part tested in testlet 'operator_overloading'
a = 2
b = a ** 3
a **= 4
autoTester.check (a, b)
autoTester.check ('Issue 277')
new = 3
autoTester.check (new)
autoTester.check ('Issue 279')
class A:
TypeError = 111
js_TypeError = 222
autoTester.check (A.TypeError, A.js_TypeError) # ... Generated code should use py_TypeError and TypeError respectively
autoTester.check ('Still alive')
autoTester.check ('Issue 301')
def filter_word (word0, word1):
if len (word0) != len (word1):
return False
for char0, char1 in zip (word0, word1):
if char0 != '_' and char0 != char1:
return False
return True
autoTester.check (filter_word ('bee', 'beer'))
autoTester.check (filter_word ('wine', 'wine'))
autoTester.check (filter_word ('win_', 'wind'))
autoTester.check (filter_word ('_in_', 'kind'))
autoTester.check (filter_word ('min_', 'kind'))
autoTester.check ('Issue 306')
dict_306 = {'Abraham': 'Lincoln', 'Barack': 'O\'Bama', 'Thomas': 'Jefferson'}
results = []
try:
while True:
results.append (dict_306.popitem ())
except Exception as exception:
autoTester.check (sorted (results))
autoTester.check ('That\'s it')
autoTester.check ('Issue 314')
try:
autoTester.check (int (float (123)))
except:
autoTester.check ('a')
try:
autoTester.check (float (12.3))
except:
autoTester.check ('b')
try:
autoTester.check (int (float ('123')))
except:
autoTester.check ('c')
try:
autoTester.check (int (float (' 123')))
except:
autoTester.check ('d')
try:
autoTester.check (float (''))
except:
autoTester.check ('e')
try:
autoTester.check (float (' '))
except:
autoTester.check ('f')
try:
autoTester.check (float ('drie'))
except:
autoTester.check ('g')
autoTester.check ('Issue 316')
autoTester.check (list (filter (None, [[1, 2], [3], [], [4, 5], [6]])))
autoTester.check (list (filter (lambda l: len (l) >= 2, [[1, 2], [3], [], [4, 5], [6]])))
autoTester.check ('Issue 317')
mylist = []
try:
mylist.remove ('value')
except ValueError as exception:
autoTester.check (exception.__class__.__name__)
autoTester.check ('Issue 331')
autoTester.check (max (-5, 4, 1, 2, -3, 2))
autoTester.check (max ([-5, 4, 1, 2, -3, 2]))
autoTester.check (max ((5, 6, 2, -2, -4)))
autoTester.check (min (-5, 4, 1, 2, -3, 2))
autoTester.check (min ([-5, 4, 1, 2, -3, 2]))
autoTester.check (min ((5, 6, 2, -2, -4)))
autoTester.check ('issue 356')
try:
raise TypeError("How are you?")
except TypeError as exception:
autoTester.check (exception)
autoTester.check ('Issue 369')
class Vector:
def __init__ (self, *values):
self.values = values
def __iter__ (self):
for item in self.values:
yield item
def __add__(self, other):
return Vector (* (x + y for x, y in zip (self, other)))
def __str__ (self):
return str (list (self.values))
#__pragma__ ('opov')
autoTester.check (str (Vector (1,2,3) + Vector (3,4,5)))
#__pragma__ ('noopov')
autoTester.check ('Issue 387')
run387 (autoTester)
autoTester.check ('Issue 391')
autoTester.check (int (False))
autoTester.check (int (True))
autoTester.check (int (1 == 2))
autoTester.check (int (1 != 2))
autoTester.check ('Issue 392')
class Example:
d = {'A': 1, 'B': 2}
rec = re.compile ('(?P\d+)', re.ASCII)
def run(self):
match = self.rec.match ('42')
if not match:
print('ERROR: RE does not match')
e = match.groupdict ()
autoTester.check ("before: self.d=", self.d)
autoTester.check ("before: e=", e)
self.d.update (e)
autoTester.check ("after: self.d=", self.d)
example = Example ()
example.run ()
autoTester.check ('Issue 398')
# This used to give extra comma's so invalid syntax (no check calls needed)
class Test398 (object):
#__pragma__ ('skip')
def method1 (self):
pass
def method2 (self):
pass
#__pragma__ ('noskip')
pass
test398 = Test398 ()
autoTester.check ('Issue 399')
__pragma__ ('keycheck')
try:
surpressWarning = {'a':5}['a']
surpressWarning = {'a':5}['b']
autoTester.check ('no problem')
except KeyError:
autoTester.check ('not found')
autoTester.check ('Issue 413')
__pragma__ ('nokeycheck')
class Foo:
def __len__ (self):
return 3
def __getitem__ (self, i):
if i >= 3:
raise IndexError
return 'This is item ' + str (i)
foo = Foo ()
#__pragma__ ('opov')
autoTester.check ('Attempt 1:')
for i in foo:
autoTester.check (i)
autoTester.check ('Attempt 2:')
for i in range (len (foo)):
autoTester.check (foo [i])
#__pragma__('noopov')
autoTester.check ('Issue 414')
class Foo:
pass
foo = Foo ()
foo.bar = 'baz'
foo.name = 'hello'
foo.default = 'world'
autoTester.check ([x for x in dir (foo) if not x.startswith ('__')])
#__pragma__('kwargs')
def foo (*args, **kwargs):
default = kwargs.get ('default', 'bar')
return default
autoTester.check (foo())
autoTester.check (foo(default = 'Hello World'))
autoTester.check ('Issue 460')
s460 = 'car'
l460 = [11, 22, 33]
t460 = (4, 5, 6)
d460 = {-1: 'mmminusOne', 'b': 'bbbike'}
#__pragma__ ('opov')
l460 [0] = 1
l460 [-2] = 2
l460 [-1] = 3
d460 [-1] = 'minusOne'
d460 ['b'] = 'bike'
autoTester.check (s460 [0], s460 [1], s460 [2], s460 [-1], s460 [-2], s460 [-3])
autoTester.check (l460 [0], l460 [1], l460 [2], l460 [-1], l460 [-2], l460 [-3])
autoTester.check (t460 [0], t460 [1], t460 [2], t460 [-1], t460 [-2], t460 [-3])
autoTester.check (d460 [-1], d460 ['b'])
autoTester.check (s460 [0], s460 [1], s460 [2], s460 [-1], s460 [-2], s460 [-3])
autoTester.check (l460 [0], l460 [1], l460 [2], l460 [-1], l460 [-2], l460 [-3])
autoTester.check (t460 [0], t460 [1], t460 [2], t460 [-1], t460 [-2], t460 [-3])
autoTester.check (d460 [-1], d460 ['b'])
#__pragma__ ('noopov')
#__pragma__ ('keycheck')
try:
autoTester.check (d460 [-1], d460 ['c'])
except:
autoTester.check (111)
try:
autoTester.check (d460 [-2], d460 ['b'])
except:
autoTester.check (222)
#__pragma__ ('nokeycheck')
a = [1, 2, 3]
b = [4, 5, 6]
c = '1,2,34,5,6'
if __envir__.executor_name == __envir__.transpiler_name:
autoTester.check (a + b)
autoTester.check (a + b) #__:opov
autoTester.check (a + b)
else:
autoTester.check (c)
autoTester.check (a + b) #__:opov
autoTester.check (c)
#__pragma__ ('opov')
if __envir__.executor_name == __envir__.transpiler_name:
autoTester.check (a + b) #__:noopov
autoTester.check (a + b)
autoTester.check (a + b) #__:noopov
else:
autoTester.check (c) #__:noopov
autoTester.check (a + b)
autoTester.check (c) #__:noopov
#__pragma__ ('noopov')
autoTester.check ('Issue 494') # {None} in formatted string gets converted to {}
# Worked, should still work
a = 1
autoTester.check (f'a={a}')
# Failed, should now work
a = None
autoTester.check (f'a={a}')
autoTester.check ('Issue 515') # Method format() is failing to replace the replacement fields if the value is None
autoTester.check('a: {}; b: {}'.format(None, 1))
autoTester.check('a: {}; b: {}'.format(1, None))
autoTester.check('a: {0}; b: {1}'.format(1, None))
autoTester.check('a: {0}; b: {1}'.format(1, []))
autoTester.check('a: {}; b: {}'.format(1, []))
autoTester.check('a: {0}; b: {1}'.format(1, {}))
autoTester.check('a: {}; b: {}'.format(1, {}))
autoTester.check('a: {0}; b: {1}'.format(1, 0))
autoTester.check('a: {}; b: {}'.format(1, 0))
autoTester.check ('Issue 559') # Reexport everything imported, e.g. by the __init__.py of a module
run559 (autoTester)
”h]”hX'F from org.transcrypt.stubs.browser import __pragma__, __new__, __envir__, __symbols__
from div_issues.issue55 import * # Names not exported from package's __init__.py, no output, only compilation check
from div_issues.issue387 import run387 # Support __module__ and __qualname__ for introspection (only __module__ done and
# __name__ set to '__main__ for main module'
from div_issues.issue559 import run559 # Imported names not reexported form the __init__.py of a module
import re
def run (autoTester):
autoTester.check ('Issue 24') # Non keyword switch generates javascript SyntaxError
switch = False
autoTester.check (switch)
autoTester.check ('Issue 27') # Python list.index () not translated correctly
autoTester.check (['zero', 'one', 'two', 'three', 'four'] .index ('three'))
autoTester.check ('Issue 36') # Bug in compiling lambda default argument values
# Workaround for Python closures capturing variables rather than values
# An extra enclosing scope is created to remember the value of the variable
results = []
for i in range (10):
# results.append (lambda: i) # Works nowhere
# results.append (lambda j = i: j) # Works only in Python
results.append ((lambda j: lambda: j) (i)) # Works in Python and Transcrypt
autoTester.check ([result () for result in results])
autoTester.check ('Issue 37') # Python integer division not translated correctly
autoTester.check (15 // 7)
autoTester.check ('Issue 40') # Python parentheses dropped during translation
autoTester.check (65 / (5 * 2))
autoTester.check ('Issue 50') # Wrong answer with parentheses moved during translation
autoTester.check ((240 + 30 - 1) // 30 * 30)
autoTester.check ('Issue 51') # Wrong answer with set() compare
a = 1
b = 1
autoTester.check (a, b, {a, b} == {1, 2})
autoTester.check ('Issue 52') # Non keyword 'default' generates javascript SyntaxError
switch, case, default = 'switch', 'case', 'default'
autoTester.check (switch, case, default)
autoTester.check ('Issue 54') # Type dict missing clear(), setdefault()
aDict = {1: 11, 2: 22, 3: 33}
autoTester.check (aDict)
aDict.clear ()
autoTester.check (aDict)
autoTester.check ('Issue 60') # Python bool() not translated
three = 3
one = three & 1
seven = three | 4
eight = one << 3
four = eight >> 1
aTrue = bool (three & one)
aFalse = bool (three & four)
autoTester.check (3, three, 1, one, 7, seven, 8, eight, 4, four, True, aTrue, False, aFalse)
autoTester.check ('Issue 65') # Adding two lists with + not supported
__pragma__ ('opov')
aList = [4, 5, 6]
autoTester.check ([1, 2, 3,] + aList + [4, 5, 6])
autoTester.check (3 * [1, 2, 3])
autoTester.check ([1, 2, 3] * 3)
aString = 'Crocodile'
autoTester.check ('Tiger' + aString + 'Elephant')
autoTester.check (3 * aString)
autoTester.check (aString * 3)
__pragma__ ('noopov')
autoTester.check ('Issue 76') # Python //= not translated correctly
initially17 = 17
autoTester.check (initially17)
initially17 //= 2
autoTester.check (initially17)
initially17 //= 2
autoTester.check (initially17)
autoTester.check ('Issue 112') # When using -e6, iterating TypedArrays or other non-list Iterables doesn't work
try:
if __envir__.executor_name == __envir__.transpiler_name: # CPython doesn't know Int8Array
x = __new__ (Int8Array (2))
else:
x = [None, None]
x [0] = 3
x [1] = 2
for i in x:
autoTester.check (i)
y = 3
for j in y:
autoTester.check (j)
except: # No 'Exception' can be used behind this, since this is a JavaScript exception, and no subclass of Exception. ??? How desirable is this behaviour?
pass
# autoTester.check ('Detected iterating over non-iterable') # Minifier masks this exception, so we'll have to pass
autoTester.check ('Issue 122') # Problem with yield (or rather with slicing beyond list end)
def chunks (aList, chunkLength):
for index in range (0, len (aList), chunkLength):
yield aList [index : index + chunkLength]
for chunk in chunks ([chr (index + 97) for index in range (26)], 10):
autoTester.check (chunk)
autoTester.check ('Issue 123') # Python % shouldn't behave like JS %
autoTester.check (10 % 3, 10 % -3, -10 % 3, -10 % -3, 10 % 10, 10 % -10, -10 % 10, -10 % -10)
autoTester.check ('Issue 125') # Strings not iterable
abc = 'abc'
for index in abc:
autoTester.check (abc)
autoTester.check ('Issue 127') # Can't use the key 'keys' in a dict
autoTester.check ({"include_docs": "true", "keys": ["key1", "key2"], "limit": 50})
autoTester.check ('Issue 134') # Operator %= translated incorrectly
x0, x1, x2, x3, x4, x5 = 5, 12, -5, -5, 0, 0
x0 %= 10; x1 %= 5; x2 %= 2; x3 %= -3; x4 %= 1; x5 %= -1000
autoTester.check (x0, x1, x2, x3, x4)
autoTester.check ('Issue 136') # Method dict.get(key[, default]) not implemented
aDict = {'a': 'ape', 'b': 'banana'}
autoTester.check (aDict.get ('a', 'noApe'), aDict.get ('b'), aDict.get ('c', 'noCarot'), aDict.get ('d'))
autoTester.check ('Issue 144')
__pragma__('opov')
aList = [x for x in [1, 2, 3]]
autoTester.check (aList)
__pragma__('noopov')
autoTester.check ('
Issue 145
') # List sorting incorrect in case of multiple columns
class SortTest:
def __init__ (self):
self.alphabet = 'abcdefghijklmnopqrstuvwxyz'
self.nChars = 10
self.nCols = 10
self.nRows = 30
self.pseudoRandom = 0
def randomWord ():
word = ''
for iChar in range (self.nChars):
self.pseudoRandom = (81212 * self.pseudoRandom + 28411) % 134456
# self.pseudoRandom = (1234 * self.pseudoRandom + 57) % 137 # Deliberately short period
word += self.alphabet [self.pseudoRandom % 26]
return word
self.rows = [[randomWord () for iCol in range (self.nCols)] for iRow in range (self.nRows)]
def sort (self):
for iCol in reversed (range (self.nCols)):
self.rows.sort (key = lambda row: row [iCol])
sortTest = SortTest ()
autoTester.check ('
Unsorted:
')
for row in sortTest.rows:
autoTester.check ('{}
'.format (','.join ([word for word in row])))
sortTest.sort ()
autoTester.check ('
Sorted:
')
for row in sortTest.rows:
autoTester.check ('{}
'.format (','.join ([word for word in row])))
autoTester.check ('
Issue 148
') # Allow key a.o. key 'items' in dict
aDict = {
'items': [4, 5, 6]
}
for aKey, aValue in aDict.items ():
autoTester.check ('{}: {}'.format (aKey, aValue))
autoTester.check ('
Issue 169
') # Add support for float('inf') and float('-inf')
autoTester.check (int (1 / float ('inf')), int (1 / float ('-inf')))
autoTester.check ('
Issue 178
') # List Comprehensions / Operator Precedence Bug
bitmaps = [
(2 , ''),
(4 , ''),
(8, 'i'),
(16, 'm'),
(32, 'y'),
(64, 'u'),
(128, 'g')
]
for flags in (122, 233, 11, 55, 79, 201, 23, 111, 200, 100, 50, 25, 12, 6):
autoTester.check (''.join ([x [1] for x in bitmaps if (x [0] & flags) > 0]))
def issue256 ():
autoTester.check ('Issue 256')
class C:
def __init__ (self, value):
self.value = value
def f1 (value): # Generate parens after return
return (C (value) .value or 'second') .capitalize () == 'First'
def f2 (value): # Generate parens after return
return (C (value) .value or 'second') .capitalize () == 'Second'
def f3 (value): # Generate NO parens after return
return C (value) .value or 'second'
def f4 (value): # Generate NO parens after return
return (C (value) .value or 'second')
autoTester.check (f1 ('first'))
autoTester.check (f1 (''))
autoTester.check (f2 ('first'))
autoTester.check (f2 (''))
autoTester.check (f3 ('first'))
autoTester.check (f4 (''))
issue256 ()
autoTester.check ('Issue 274')
a = 3
del a
autoTester.check ('Still alive')
autoTester.check ('Issue 276') # Partial, other part tested in testlet 'operator_overloading'
a = 2
b = a ** 3
a **= 4
autoTester.check (a, b)
autoTester.check ('Issue 277')
new = 3
autoTester.check (new)
autoTester.check ('Issue 279')
class A:
TypeError = 111
js_TypeError = 222
autoTester.check (A.TypeError, A.js_TypeError) # ... Generated code should use py_TypeError and TypeError respectively
autoTester.check ('Still alive')
autoTester.check ('Issue 301')
def filter_word (word0, word1):
if len (word0) != len (word1):
return False
for char0, char1 in zip (word0, word1):
if char0 != '_' and char0 != char1:
return False
return True
autoTester.check (filter_word ('bee', 'beer'))
autoTester.check (filter_word ('wine', 'wine'))
autoTester.check (filter_word ('win_', 'wind'))
autoTester.check (filter_word ('_in_', 'kind'))
autoTester.check (filter_word ('min_', 'kind'))
autoTester.check ('Issue 306')
dict_306 = {'Abraham': 'Lincoln', 'Barack': 'O\'Bama', 'Thomas': 'Jefferson'}
results = []
try:
while True:
results.append (dict_306.popitem ())
except Exception as exception:
autoTester.check (sorted (results))
autoTester.check ('That\'s it')
autoTester.check ('Issue 314')
try:
autoTester.check (int (float (123)))
except:
autoTester.check ('a')
try:
autoTester.check (float (12.3))
except:
autoTester.check ('b')
try:
autoTester.check (int (float ('123')))
except:
autoTester.check ('c')
try:
autoTester.check (int (float (' 123')))
except:
autoTester.check ('d')
try:
autoTester.check (float (''))
except:
autoTester.check ('e')
try:
autoTester.check (float (' '))
except:
autoTester.check ('f')
try:
autoTester.check (float ('drie'))
except:
autoTester.check ('g')
autoTester.check ('Issue 316')
autoTester.check (list (filter (None, [[1, 2], [3], [], [4, 5], [6]])))
autoTester.check (list (filter (lambda l: len (l) >= 2, [[1, 2], [3], [], [4, 5], [6]])))
autoTester.check ('Issue 317')
mylist = []
try:
mylist.remove ('value')
except ValueError as exception:
autoTester.check (exception.__class__.__name__)
autoTester.check ('Issue 331')
autoTester.check (max (-5, 4, 1, 2, -3, 2))
autoTester.check (max ([-5, 4, 1, 2, -3, 2]))
autoTester.check (max ((5, 6, 2, -2, -4)))
autoTester.check (min (-5, 4, 1, 2, -3, 2))
autoTester.check (min ([-5, 4, 1, 2, -3, 2]))
autoTester.check (min ((5, 6, 2, -2, -4)))
autoTester.check ('issue 356')
try:
raise TypeError("How are you?")
except TypeError as exception:
autoTester.check (exception)
autoTester.check ('Issue 369')
class Vector:
def __init__ (self, *values):
self.values = values
def __iter__ (self):
for item in self.values:
yield item
def __add__(self, other):
return Vector (* (x + y for x, y in zip (self, other)))
def __str__ (self):
return str (list (self.values))
#__pragma__ ('opov')
autoTester.check (str (Vector (1,2,3) + Vector (3,4,5)))
#__pragma__ ('noopov')
autoTester.check ('Issue 387')
run387 (autoTester)
autoTester.check ('Issue 391')
autoTester.check (int (False))
autoTester.check (int (True))
autoTester.check (int (1 == 2))
autoTester.check (int (1 != 2))
autoTester.check ('Issue 392')
class Example:
d = {'A': 1, 'B': 2}
rec = re.compile ('(?P\d+)', re.ASCII)
def run(self):
match = self.rec.match ('42')
if not match:
print('ERROR: RE does not match')
e = match.groupdict ()
autoTester.check ("before: self.d=", self.d)
autoTester.check ("before: e=", e)
self.d.update (e)
autoTester.check ("after: self.d=", self.d)
example = Example ()
example.run ()
autoTester.check ('Issue 398')
# This used to give extra comma's so invalid syntax (no check calls needed)
class Test398 (object):
#__pragma__ ('skip')
def method1 (self):
pass
def method2 (self):
pass
#__pragma__ ('noskip')
pass
test398 = Test398 ()
autoTester.check ('Issue 399')
__pragma__ ('keycheck')
try:
surpressWarning = {'a':5}['a']
surpressWarning = {'a':5}['b']
autoTester.check ('no problem')
except KeyError:
autoTester.check ('not found')
autoTester.check ('Issue 413')
__pragma__ ('nokeycheck')
class Foo:
def __len__ (self):
return 3
def __getitem__ (self, i):
if i >= 3:
raise IndexError
return 'This is item ' + str (i)
foo = Foo ()
#__pragma__ ('opov')
autoTester.check ('Attempt 1:')
for i in foo:
autoTester.check (i)
autoTester.check ('Attempt 2:')
for i in range (len (foo)):
autoTester.check (foo [i])
#__pragma__('noopov')
autoTester.check ('Issue 414')
class Foo:
pass
foo = Foo ()
foo.bar = 'baz'
foo.name = 'hello'
foo.default = 'world'
autoTester.check ([x for x in dir (foo) if not x.startswith ('__')])
#__pragma__('kwargs')
def foo (*args, **kwargs):
default = kwargs.get ('default', 'bar')
return default
autoTester.check (foo())
autoTester.check (foo(default = 'Hello World'))
autoTester.check ('Issue 460')
s460 = 'car'
l460 = [11, 22, 33]
t460 = (4, 5, 6)
d460 = {-1: 'mmminusOne', 'b': 'bbbike'}
#__pragma__ ('opov')
l460 [0] = 1
l460 [-2] = 2
l460 [-1] = 3
d460 [-1] = 'minusOne'
d460 ['b'] = 'bike'
autoTester.check (s460 [0], s460 [1], s460 [2], s460 [-1], s460 [-2], s460 [-3])
autoTester.check (l460 [0], l460 [1], l460 [2], l460 [-1], l460 [-2], l460 [-3])
autoTester.check (t460 [0], t460 [1], t460 [2], t460 [-1], t460 [-2], t460 [-3])
autoTester.check (d460 [-1], d460 ['b'])
autoTester.check (s460 [0], s460 [1], s460 [2], s460 [-1], s460 [-2], s460 [-3])
autoTester.check (l460 [0], l460 [1], l460 [2], l460 [-1], l460 [-2], l460 [-3])
autoTester.check (t460 [0], t460 [1], t460 [2], t460 [-1], t460 [-2], t460 [-3])
autoTester.check (d460 [-1], d460 ['b'])
#__pragma__ ('noopov')
#__pragma__ ('keycheck')
try:
autoTester.check (d460 [-1], d460 ['c'])
except:
autoTester.check (111)
try:
autoTester.check (d460 [-2], d460 ['b'])
except:
autoTester.check (222)
#__pragma__ ('nokeycheck')
a = [1, 2, 3]
b = [4, 5, 6]
c = '1,2,34,5,6'
if __envir__.executor_name == __envir__.transpiler_name:
autoTester.check (a + b)
autoTester.check (a + b) #__:opov
autoTester.check (a + b)
else:
autoTester.check (c)
autoTester.check (a + b) #__:opov
autoTester.check (c)
#__pragma__ ('opov')
if __envir__.executor_name == __envir__.transpiler_name:
autoTester.check (a + b) #__:noopov
autoTester.check (a + b)
autoTester.check (a + b) #__:noopov
else:
autoTester.check (c) #__:noopov
autoTester.check (a + b)
autoTester.check (c) #__:noopov
#__pragma__ ('noopov')
autoTester.check ('Issue 494') # {None} in formatted string gets converted to {}
# Worked, should still work
a = 1
autoTester.check (f'a={a}')
# Failed, should now work
a = None
autoTester.check (f'a={a}')
autoTester.check ('Issue 515') # Method format() is failing to replace the replacement fields if the value is None
autoTester.check('a: {}; b: {}'.format(None, 1))
autoTester.check('a: {}; b: {}'.format(1, None))
autoTester.check('a: {0}; b: {1}'.format(1, None))
autoTester.check('a: {0}; b: {1}'.format(1, []))
autoTester.check('a: {}; b: {}'.format(1, []))
autoTester.check('a: {0}; b: {1}'.format(1, {}))
autoTester.check('a: {}; b: {}'.format(1, {}))
autoTester.check('a: {0}; b: {1}'.format(1, 0))
autoTester.check('a: {}; b: {}'.format(1, 0))
autoTester.check ('Issue 559') # Reexport everything imported, e.g. by the __init__.py of a module
run559 (autoTester)
”…”�”}”(hhhjã ubah}”(h ]”h"]”h$]”h&]”h(]”Œsource”Œv/home/jac/active/geatec/transcrypt/Transcrypt/transcrypt/development/automated_tests/transcrypt/div_issues/__init__.py”hŒh�hމh�}”h‘Ksuh*hzhh+hKyhjÒ ubeh}”(h ]”Œid16”ah"]”h–ah$]”h&]”h(]”Œ
literal_block”ˆuh*hehjÁ hhhhhNubeh}”(h ]”(Œdiverse-issues”j¸ eh"]”h$]”(Œdiverse issues”Œautotest_docstrings”eh&]”h(]”uh*h
hhhhhh+hKwhî}”j j® shð}”j¸ j® subh)�”}”(hhh]”(h)�”}”(hŒ
Diverse pulls”h]”hŒ
Diverse pulls”…”�”}”(hj hj
hhhNhNubah}”(h ]”h"]”h$]”h&]”h(]”uh*hhj hhhh+hK~ubhf)�”}”(hhh]”(hk)�”}”(hŒTestlet: div_pulls”h]”hŒTestlet: div_pulls”…”�”}”(hj hj ubah}”(h ]”h"]”h$]”h&]”h(]”uh*hjhh+hK€hj ubh{)�”}”(hXG # Also contains small enhancements
import div_pulls.pull575_reexport_modules as pull575
'This is a single line docstring'
class A:
'''
This
is
a
multiline
docstring
'''
def __init__ (self, x):
'This is a single line comment'
self.x = x
'''
This
is
a
multiline
docstring
'''
'This is a single line docstring'
'''
This
is
a
multiline
docstring
'''
a = A (5.5)
def run (autoTester):
autoTester.check ('Pull 56')
s = 'abcdefghij'
autoTester.check (s [2:3])
autoTester.check (s [:3])
autoTester.check (s [2:])
autoTester.check (s [::2])
autoTester.check ('Pull 59')
autoTester.check (list (filter (lambda x: x % 2 == 0, range (10))))
autoTester.check (list (map (lambda x: x*x, range (0, 31, 3))))
autoTester.check ('Pull 561')
def brackets (word):
autoTester.check ('sideeffect')
return '[' + word + ']'
autoTester.check (brackets ('anything') .lower ()) #__:opov
pull575.run (autoTester)
”h]”hXG # Also contains small enhancements
import div_pulls.pull575_reexport_modules as pull575
'This is a single line docstring'
class A:
'''
This
is
a
multiline
docstring
'''
def __init__ (self, x):
'This is a single line comment'
self.x = x
'''
This
is
a
multiline
docstring
'''
'This is a single line docstring'
'''
This
is
a
multiline
docstring
'''
a = A (5.5)
def run (autoTester):
autoTester.check ('Pull 56')
s = 'abcdefghij'
autoTester.check (s [2:3])
autoTester.check (s [:3])
autoTester.check (s [2:])
autoTester.check (s [::2])
autoTester.check ('Pull 59')
autoTester.check (list (filter (lambda x: x % 2 == 0, range (10))))
autoTester.check (list (map (lambda x: x*x, range (0, 31, 3))))
autoTester.check ('Pull 561')
def brackets (word):
autoTester.check ('sideeffect')
return '[' + word + ']'
autoTester.check (brackets ('anything') .lower ()) #__:opov
pull575.run (autoTester)
”…”�”}”(hhhj) ubah}”(h ]”h"]”h$]”h&]”h(]”Œsource”Œu/home/jac/active/geatec/transcrypt/Transcrypt/transcrypt/development/automated_tests/transcrypt/div_pulls/__init__.py”hŒh�hމh�}”h‘Ksuh*hzhh+hK€hj ubeh}”(h ]”Œid17”ah"]”h–ah$]”h&]”h(]”Œ
literal_block”ˆuh*hehj hhhhhNubeh}”(h ]”Œ
diverse-pulls”ah"]”h$]”Œ
diverse pulls”ah&]”h(]”uh*h
hhhhhh+hK~ubh)�”}”(hhh]”(h)�”}”(hŒ2Docstrings: __doc__ attribute generated optionally”h]”hŒ2Docstrings: __doc__ attribute generated optionally”…”�”}”(hjO hjM hhhNhNubah}”(h ]”h"]”h$]”h&]”h(]”uh*hhjJ hhhh+hK…ubh-)�”}”(hŒàTo keep the generated code lean, generation of *__doc__* attributes is controlled per module by *__pragma__ ('docat')* or by the *-d* / *--docat* command line switch, combined with user per module of *__pragma__ ('nodocat')*”h]”(hŒ/To keep the generated code lean, generation of ”…”�”}”(hŒ/To keep the generated code lean, generation of ”hj[ hhhNhNubh8)�”}”(hŒ *__doc__*”h]”hŒ__doc__”…”�”}”(hhhjd ubah}”(h ]”h"]”h$]”h&]”h(]”uh*h7hj[ ubhŒ( attributes is controlled per module by ”…”�”}”(hŒ( attributes is controlled per module by ”hj[ hhhNhNubh8)�”}”(hŒ*__pragma__ ('docat')*”h]”hŒ__pragma__ (‘docat’)”…”�”}”(hhhjw ubah}”(h ]”h"]”h$]”h&]”h(]”uh*h7hj[ ubhŒ or by the ”…”�”}”(hŒ or by the ”hj[ hhhNhNubh8)�”}”(hŒ*-d*”h]”hŒ-d”…”�”}”(hhhjŠ ubah}”(h ]”h"]”h$]”h&]”h(]”uh*h7hj[ ubhŒ / ”…”�”}”(hŒ / ”hj[ hhhNhNubh8)�”}”(hŒ *--docat*”h]”hŒâ€“docat”…”�”}”(hhhj� ubah}”(h ]”h"]”h$]”h&]”h(]”uh*h7hj[ ubhŒ7 command line switch, combined with user per module of ”…”�”}”(hŒ7 command line switch, combined with user per module of ”hj[ hhhNhNubh8)�”}”(hŒ*__pragma__ ('nodocat')*”h]”hŒ__pragma__ (‘nodocat’)”…”�”}”(hhhj° ubah}”(h ]”h"]”h$]”h&]”h(]”uh*h7hj[ ubeh}”(h ]”h"]”h$]”h&]”h(]”uh*h,hh+hK‡hjJ hhubhf)�”}”(hhh]”(hk)�”}”(hŒTestlet: docstrings”h]”hŒTestlet: docstrings”…”�”}”(hjÉ hjÇ ubah}”(h ]”h"]”h$]”h&]”h(]”uh*hjhh+hK‰hjÄ ubh{)�”}”(hX '''Just a module
to test docstrings'''
'''Not visible'''
from org.transcrypt.stubs.browser import __pragma__
__pragma__ ('docat')
def run (autoTester):
def f (p):
'''Just a function
called f'''
'''Not visible'''
autoTester.check (p)
class C:
'''Just a class
called C'''
'''Not visible'''
def g (self, q):
'''Just a method
called g'''
'''Not visible'''
autoTester.check (q)
autoTester.check (__doc__)
autoTester.check ()
autoTester.check (f.__doc__)
autoTester.check ()
autoTester.check (C.__doc__)
autoTester.check ()
autoTester.check (C.g.__doc__)
autoTester.check ()
f ('Doc')
C () .g ('strings')
”h]”hX '''Just a module
to test docstrings'''
'''Not visible'''
from org.transcrypt.stubs.browser import __pragma__
__pragma__ ('docat')
def run (autoTester):
def f (p):
'''Just a function
called f'''
'''Not visible'''
autoTester.check (p)
class C:
'''Just a class
called C'''
'''Not visible'''
def g (self, q):
'''Just a method
called g'''
'''Not visible'''
autoTester.check (q)
autoTester.check (__doc__)
autoTester.check ()
autoTester.check (f.__doc__)
autoTester.check ()
autoTester.check (C.__doc__)
autoTester.check ()
autoTester.check (C.g.__doc__)
autoTester.check ()
f ('Doc')
C () .g ('strings')
”…”�”}”(hhhjÕ ubah}”(h ]”h"]”h$]”h&]”h(]”Œsource”Œv/home/jac/active/geatec/transcrypt/Transcrypt/transcrypt/development/automated_tests/transcrypt/docstrings/__init__.py”hŒh�hމh�}”h‘Ksuh*hzhh+hK‰hjÄ ubeh}”(h ]”Œid18”ah"]”h–ah$]”h&]”h(]”Œ
literal_block”ˆuh*hehjJ hhhhhNubeh}”(h ]”Œ-docstrings-doc-attribute-generated-optionally”ah"]”h$]”Œ2docstrings: __doc__ attribute generated optionally”ah&]”h(]”uh*h
hhhhhh+hK…ubh)�”}”(hhh]”(h)�”}”(hŒ.Exceptions: exception class hierarchy, finally”h]”hŒ.Exceptions: exception class hierarchy, finally”…”�”}”(hjû hjù hhhNhNubah}”(h ]”h"]”h$]”h&]”h(]”uh*hhjö hhhh+hKŽubhf)�”}”(hhh]”(hk)�”}”(hŒTestlet: exceptions”h]”hŒTestlet: exceptions”…”�”}”(hj hj
ubah}”(h ]”h"]”h$]”h&]”h(]”uh*hjhh+hK�hj ubh{)�”}”(hXÊ from org.transcrypt.stubs.browser import __envir__, __new__, __pragma__
class Ex1 (Exception):
pass
class Ex2 (Ex1):
pass
class Ex3 (Exception):
pass
class Table (BaseException): # Any Python exception MUST inherit from BaseException
def __init__ (self, *args):
self.fields = args
def __repr__ (self):
return 'Table' + repr (self.fields) .replace (', ', ',') .replace ('\'', '')
def test1 ():
raise (Exception ('mary'))
def test2 (autoTester):
try:
test1 ()
except Ex1 as exception:
autoTester.check (111)
autoTester.check (exception)
except Exception as exception:
autoTester.check (222)
autoTester.check (exception)
def run (autoTester):
test2 (autoTester)
try:
raise Ex2 ('had')
except Ex1 as exception:
autoTester.check ('a')
except Exception as exception:
autoTester.check ('little')
autoTester.check (exception)
autoTester.check (333)
try:
raise Ex1 ('lamb')
except Ex2 as exception:
autoTester.check ('his')
autoTester.check (exception)
except Ex1 as exception:
autoTester.check ('fleece')
autoTester.check (exception)
except Exception as exception:
autoTester.check ('was')
autoTester.check (exception)
finally:
autoTester.check ('white')
autoTester.check (444)
def test3 ():
raise Ex3 ('as')
autoTester.check (555)
try:
test3 ()
except Ex1 as exception:
autoTester.check ('snow')
autoTester.check (exception)
except Exception as exception:
autoTester.check ('and')
autoTester.check (exception)
finally:
autoTester.check ('everywhere')
autoTester.check (666)
try:
raise Ex3 ('that')
except Ex1 as exception:
autoTester.check ('mary')
autoTester.check (exception)
except:
autoTester.check ('went')
finally:
autoTester.check ('the')
autoTester.check (777)
try:
try:
raise Ex3 ('lamb')
except Ex1 as exception:
autoTester.check ('was')
autoTester.check (exception)
finally:
autoTester.check ('to')
except Ex3 as exception: # We should get here, exception not swallowed
autoTester.check ('go')
autoTester.check (exception)
try:
raise __new__ (Table ('he', 'followed', 'her'))
except Ex1 as exception:
autoTester.check ('to')
autoTester.check (exception)
except Table as exception: # Pure JavaScript exception, if no Python __class__
autoTester.check ('school')
autoTester.check (exception)
except Ex3 as exception:
autoTester.check ('one')
autoTester.check (exception)
finally:
autoTester.check ('day')
try:
assert 2 * 8 / 4 == 2, 'Assert error 1'
except AssertionError as exception:
autoTester.check (exception)
try:
assert 2 * 8 / 4 == 4, 'Assert error 2'
except AssertionError as exception:
autoTester.check (exception)
try:
assert 2 * 8 / 4 == 2
except AssertionError as exception:
autoTester.check (exception)
try:
assert 2 * 8 / 4 == 4
except AssertionError as exception:
autoTester.check (exception)
autoTester.check (888)
try:
autoTester.check ('hello world 1')
except:
autoTester.check ('error 1')
else:
autoTester.check ('no error 1')
i = 1 + 2
try:
autoTester.check ('hello world 2')
if i == 3: # Prevent unreachable code warning
raise Exception ()
except:
autoTester.check ('error 2')
else:
autoTester.check ('no error 2')
for raiseIt in (False, True):
try:
try:
if raiseIt:
raise Exception ()
autoTester.check ('no error 3')
finally:
autoTester.check ('anyhow 3')
except:
autoTester.check ('error 3')
”• h]”hXÊ from org.transcrypt.stubs.browser import __envir__, __new__, __pragma__
class Ex1 (Exception):
pass
class Ex2 (Ex1):
pass
class Ex3 (Exception):
pass
class Table (BaseException): # Any Python exception MUST inherit from BaseException
def __init__ (self, *args):
self.fields = args
def __repr__ (self):
return 'Table' + repr (self.fields) .replace (', ', ',') .replace ('\'', '')
def test1 ():
raise (Exception ('mary'))
def test2 (autoTester):
try:
test1 ()
except Ex1 as exception:
autoTester.check (111)
autoTester.check (exception)
except Exception as exception:
autoTester.check (222)
autoTester.check (exception)
def run (autoTester):
test2 (autoTester)
try:
raise Ex2 ('had')
except Ex1 as exception:
autoTester.check ('a')
except Exception as exception:
autoTester.check ('little')
autoTester.check (exception)
autoTester.check (333)
try:
raise Ex1 ('lamb')
except Ex2 as exception:
autoTester.check ('his')
autoTester.check (exception)
except Ex1 as exception:
autoTester.check ('fleece')
autoTester.check (exception)
except Exception as exception:
autoTester.check ('was')
autoTester.check (exception)
finally:
autoTester.check ('white')
autoTester.check (444)
def test3 ():
raise Ex3 ('as')
autoTester.check (555)
try:
test3 ()
except Ex1 as exception:
autoTester.check ('snow')
autoTester.check (exception)
except Exception as exception:
autoTester.check ('and')
autoTester.check (exception)
finally:
autoTester.check ('everywhere')
autoTester.check (666)
try:
raise Ex3 ('that')
except Ex1 as exception:
autoTester.check ('mary')
autoTester.check (exception)
except:
autoTester.check ('went')
finally:
autoTester.check ('the')
autoTester.check (777)
try:
try:
raise Ex3 ('lamb')
except Ex1 as exception:
autoTester.check ('was')
autoTester.check (exception)
finally:
autoTester.check ('to')
except Ex3 as exception: # We should get here, exception not swallowed
autoTester.check ('go')
autoTester.check (exception)
try:
raise __new__ (Table ('he', 'followed', 'her'))
except Ex1 as exception:
autoTester.check ('to')
autoTester.check (exception)
except Table as exception: # Pure JavaScript exception, if no Python __class__
autoTester.check ('school')
autoTester.check (exception)
except Ex3 as exception:
autoTester.check ('one')
autoTester.check (exception)
finally:
autoTester.check ('day')
try:
assert 2 * 8 / 4 == 2, 'Assert error 1'
except AssertionError as exception:
autoTester.check (exception)
try:
assert 2 * 8 / 4 == 4, 'Assert error 2'
except AssertionError as exception:
autoTester.check (exception)
try:
assert 2 * 8 / 4 == 2
except AssertionError as exception:
autoTester.check (exception)
try:
assert 2 * 8 / 4 == 4
except AssertionError as exception:
autoTester.check (exception)
autoTester.check (888)
try:
autoTester.check ('hello world 1')
except:
autoTester.check ('error 1')
else:
autoTester.check ('no error 1')
i = 1 + 2
try:
autoTester.check ('hello world 2')
if i == 3: # Prevent unreachable code warning
raise Exception ()
except:
autoTester.check ('error 2')
else:
autoTester.check ('no error 2')
for raiseIt in (False, True):
try:
try:
if raiseIt:
raise Exception ()
autoTester.check ('no error 3')
finally:
autoTester.check ('anyhow 3')
except:
autoTester.check ('error 3')
”…”�”}”(hhhj ubah}”(h ]”h"]”h$]”h&]”h(]”Œsource”Œv/home/jac/active/geatec/transcrypt/Transcrypt/transcrypt/development/automated_tests/transcrypt/exceptions/__init__.py”hŒh�hމh�}”h‘Ksuh*hzhh+hK�hj ubeh}”(h ]”Œid19”ah"]”h–ah$]”h&]”h(]”Œ
literal_block”ˆuh*hehjö hhhhhNubeh}”(h ]”Œ,exceptions-exception-class-hierarchy-finally”ah"]”h$]”Œ.exceptions: exception class hierarchy, finally”ah&]”h(]”uh*h
hhhhhh+hKŽubh)�”}”(hhh]”(h)�”}”(hŒ0Extended slices: facilitating NumScrypt and such”h]”hŒ0Extended slices: facilitating NumScrypt and such”…”�”}”(hj> hj< hhhNhNubah}”(h ]”h"]”h$]”h&]”h(]”uh*hhj9 hhhh+hK•ubhf)�”}”(hhh]”(hk)�”}”(hŒTestlet: extended_slices”h]”hŒTestlet: extended_slices”…”�”}”(hjO hjM ubah}”(h ]”h"]”h$]”h&]”h(]”uh*hjhh+hK—hjJ ubh{)�”}”(hXI from org.transcrypt.stubs.browser import *
from org.transcrypt.stubs.browser import __pragma__, __envir__
def indices (key):
if __envir__.executor_name == __envir__.transpiler_name:
return tuple (key) if type (key) == list else key
else:
try:
return key.indices (1000000000)
except:
try:
return tuple ([indices (subkey) for subkey in key])
except:
return key
class Test:
def __init__ (self, autoTester):
self.autoTester = autoTester
def __getitem__ (self, key):
self.autoTester.check ('getitem (', indices (key), ')')
return 1234567
def __setitem__ (self, key, value):
self.autoTester.check ('setitem (', indices (key), ')', value)
def run (autoTester):
a = b = c = d = e = f = g = h = i = j = k = l = Test (autoTester)
__pragma__ ('opov')
a [1:2:3, 4:5:6] = b [7:8:9]
c [1:2:3] = d [4:5:6, 7:8:9]
e [1, 1:2:3, 3] = f [4, 4:5:6, 6]
g [1, 2, 3] = h [1, 2, 3]
i [1] = j [1]
k [1:2:3] = l [1:2:3]
”h]”hXI from org.transcrypt.stubs.browser import *
from org.transcrypt.stubs.browser import __pragma__, __envir__
def indices (key):
if __envir__.executor_name == __envir__.transpiler_name:
return tuple (key) if type (key) == list else key
else:
try:
return key.indices (1000000000)
except:
try:
return tuple ([indices (subkey) for subkey in key])
except:
return key
class Test:
def __init__ (self, autoTester):
self.autoTester = autoTester
def __getitem__ (self, key):
self.autoTester.check ('getitem (', indices (key), ')')
return 1234567
def __setitem__ (self, key, value):
self.autoTester.check ('setitem (', indices (key), ')', value)
def run (autoTester):
a = b = c = d = e = f = g = h = i = j = k = l = Test (autoTester)
__pragma__ ('opov')
a [1:2:3, 4:5:6] = b [7:8:9]
c [1:2:3] = d [4:5:6, 7:8:9]
e [1, 1:2:3, 3] = f [4, 4:5:6, 6]
g [1, 2, 3] = h [1, 2, 3]
i [1] = j [1]
k [1:2:3] = l [1:2:3]
”…”�”}”(hhhj[ ubah}”(h ]”h"]”h$]”h&]”h(]”Œsource”Œ{/home/jac/active/geatec/transcrypt/Transcrypt/transcrypt/development/automated_tests/transcrypt/extended_slices/__init__.py”hŒh�hމh�}”h‘Ksuh*hzhh+hK—hjJ ubeh}”(h ]”Œid20”ah"]”h–ah$]”h&]”h(]”Œ
literal_block”ˆuh*hehj9 hhhhhNubeh}”(h ]”Œ/extended-slices-facilitating-numscrypt-and-such”ah"]”h$]”Œ0extended slices: facilitating numscrypt and such”ah&]”h(]”uh*h
hhhhhh+hK•ubh)�”}”(hhh]”(h)�”}”(hŒ"General functions: sort and sorted”h]”hŒ"General functions: sort and sorted”…”�”}”(hj� hj hhhNhNubah}”(h ]”h"]”h$]”h&]”h(]”uh*hhj| hhhh+hKœubhf)�”}”(hhh]”(hk)�”}”(hŒTestlet: general_functions”h]”hŒTestlet: general_functions”…”�”}”(hj’ hj� ubah}”(h ]”h"]”h$]”h&]”h(]”uh*hjhh+hKžhj� ubh{)�”}”(hX0 from org.transcrypt.stubs.browser import __pragma__
class A:
foo='bar'
def __init__ (self):
self.foo2 = 'bar2'
class B (A):
foo3='bar3'
def __init__ (self):
self.foo4 = 'bar4'
class C:
def __len__ (self):
return 42
def run (autoTester):
autoTester.check ('len')
strings = ['hello', ',', 'world', '!']
instances = [C()]
collections = [
[], [1], [1, 2],
tuple(), (1,), (1, 2),
{}, {1: 1}, {1: 1, 2: 2}
]
for string in strings:
autoTester.check (len (string))
for instance in instances:
autoTester.check (len (instance))
for collection in collections:
autoTester.check (len (collection))
autoTester.check ('sort and sorted
')
a = [1, 5, 3, 2, -1]
b = ['sun', 'earth', 'moon']
autoTester.check (sorted (a))
autoTester.check (sorted (b))
a.sort ()
autoTester.check (a)
b.sort ()
autoTester.check (b)
autoTester.check (sorted (a, reverse = True))
autoTester.check (sorted (b, reverse = True))
a.sort (reverse = True)
autoTester.check (a)
b.sort (reverse = True)
autoTester.check (b)
b.sort (key = lambda x: len (x))
autoTester.check (b)
b.sort (key = lambda x: len (x), reverse = True)
autoTester.check (b)
autoTester.check ('
dir
')
autoTester.check ([entry for entry in dir (A) if not entry.startswith ('__')])
autoTester.check ([entry for entry in dir (A()) if not entry.startswith ('__')])
autoTester.check ([entry for entry in dir (B) if not entry.startswith ('__')])
autoTester.check ([entry for entry in dir (B()) if not entry.startswith ('__')])
autoTester.check ('
any, all, sum
')
list1 = ['ape', 'node', 'mice']
list2 = ['vim', '', 'jet']
list3 = ['', '', '']
list4 = [[1, 2], [1], []] # Truthyness into play
autoTester.check (list1, any (list1), all (list1))
autoTester.check (list2, any (list2), all (list2))
autoTester.check (list3, any (list3), all (list3))
autoTester.check (list4, any (list4), all (list4))
autoTester.check (sum (range (5)))
def generator1 ():
for i in range (5):
yield i;
def generator2 ():
for i in range (5):
if i % 2:
yield 0
else:
yield i;
def generator3 ():
for i in range (5):
yield 0;
autoTester.check (generator1 (), any (generator1 ()), all (generator1 ()))
autoTester.check (generator2 (), any (generator2 ()), all (generator2 ()))
autoTester.check (generator3 (), any (generator3 ()), all (generator3 ()))
autoTester.check (sum (generator1 ()))
__pragma__ ('endif')
”h]”hX0 from org.transcrypt.stubs.browser import __pragma__
class A:
foo='bar'
def __init__ (self):
self.foo2 = 'bar2'
class B (A):
foo3='bar3'
def __init__ (self):
self.foo4 = 'bar4'
class C:
def __len__ (self):
return 42
def run (autoTester):
autoTester.check ('len')
strings = ['hello', ',', 'world', '!']
instances = [C()]
collections = [
[], [1], [1, 2],
tuple(), (1,), (1, 2),
{}, {1: 1}, {1: 1, 2: 2}
]
for string in strings:
autoTester.check (len (string))
for instance in instances:
autoTester.check (len (instance))
for collection in collections:
autoTester.check (len (collection))
autoTester.check ('sort and sorted
')
a = [1, 5, 3, 2, -1]
b = ['sun', 'earth', 'moon']
autoTester.check (sorted (a))
autoTester.check (sorted (b))
a.sort ()
autoTester.check (a)
b.sort ()
autoTester.check (b)
autoTester.check (sorted (a, reverse = True))
autoTester.check (sorted (b, reverse = True))
a.sort (reverse = True)
autoTester.check (a)
b.sort (reverse = True)
autoTester.check (b)
b.sort (key = lambda x: len (x))
autoTester.check (b)
b.sort (key = lambda x: len (x), reverse = True)
autoTester.check (b)
autoTester.check ('
dir
')
autoTester.check ([entry for entry in dir (A) if not entry.startswith ('__')])
autoTester.check ([entry for entry in dir (A()) if not entry.startswith ('__')])
autoTester.check ([entry for entry in dir (B) if not entry.startswith ('__')])
autoTester.check ([entry for entry in dir (B()) if not entry.startswith ('__')])
autoTester.check ('
any, all, sum
')
list1 = ['ape', 'node', 'mice']
list2 = ['vim', '', 'jet']
list3 = ['', '', '']
list4 = [[1, 2], [1], []] # Truthyness into play
autoTester.check (list1, any (list1), all (list1))
autoTester.check (list2, any (list2), all (list2))
autoTester.check (list3, any (list3), all (list3))
autoTester.check (list4, any (list4), all (list4))
autoTester.check (sum (range (5)))
def generator1 ():
for i in range (5):
yield i;
def generator2 ():
for i in range (5):
if i % 2:
yield 0
else:
yield i;
def generator3 ():
for i in range (5):
yield 0;
autoTester.check (generator1 (), any (generator1 ()), all (generator1 ()))
autoTester.check (generator2 (), any (generator2 ()), all (generator2 ()))
autoTester.check (generator3 (), any (generator3 ()), all (generator3 ()))
autoTester.check (sum (generator1 ()))
__pragma__ ('endif')
”…”�”}”(hhhjž ubah}”(h ]”h"]”h$]”h&]”h(]”Œsource”Œ}/home/jac/active/geatec/transcrypt/Transcrypt/transcrypt/development/automated_tests/transcrypt/general_functions/__init__.py”hŒh�hމh�}”h‘Ksuh*hzhh+hKžhj� ubeh}”(h ]”Œid21”ah"]”h–ah$]”h&]”h(]”Œ
literal_block”ˆuh*hehj| hhhhhNubeh}”(h ]”Œ!general-functions-sort-and-sorted”ah"]”h$]”Œ"general functions: sort and sorted”ah&]”h(]”uh*h
hhhhhh+hKœubh)�”}”(hhh]”(h)�”}”(hŒ]”h]”hŒ]”…”�”}”(hjÄ hj hhhNhNubah}”(h ]”h"]”h$]”h&]”h(]”uh*hhj¿ hhhh+hK£ubh-)�”}”(hŒ^The *globals ()* function does the same as its counterpart in CPython, with some restrictions.”h]”(hŒThe ”…”�”}”(hŒThe ”hjÐ hhhNhNubh8)�”}”(hŒ*globals ()*”h]”hŒ
globals ()”…”�”}”(hhhjÙ ubah}”(h ]”h"]”h$]”h&]”h(]”uh*h7hjÐ ubhŒN function does the same as its counterpart in CPython, with some restrictions.”…”�”}”(hŒN function does the same as its counterpart in CPython, with some restrictions.”hjÐ hhhNhNubeh}”(h ]”h"]”h$]”h&]”h(]”uh*h,hh+hK¥hj¿ hhubh-)�”}”(hŒIn the same module:”h]”hŒIn the same module:”…”�”}”(hjô hjò hhhNhNubah}”(h ]”h"]”h$]”h&]”h(]”uh*h,hh+hK§hj¿ hhubh Œbullet_list”“”)�”}”(hhh]”(h Œ list_item”“”)�”}”(hŒj*globals ()* can retrieve all module-level variables, wether created via *globals ()* or in the normal way”h]”h-)�”}”(hj h]”(h8)�”}”(hŒ*globals ()*”h]”hŒ
globals ()”…”�”}”(hhhj ubah}”(h ]”h"]”h$]”h&]”h(]”uh*h7hj ubhŒ= can retrieve all module-level variables, wether created via ”…”�”}”(hŒ= can retrieve all module-level variables, wether created via ”hj ubh8)�”}”(hŒ*globals ()*”h]”hŒ
globals ()”…”�”}”(hhhj! ubah}”(h ]”h"]”h$]”h&]”h(]”uh*h7hj ubhŒ or in the normal way”…”�”}”(hŒ or in the normal way”hj ubeh}”(h ]”h"]”h$]”h&]”h(]”uh*h,hh+hK©hj ubah}”(h ]”h"]”h$]”h&]”h(]”uh*j hj hhhh+hNubj )�”}”(hŒpmodule-level variables created via *globals ()* can only be retrieved by *globals ()*, not as a normal variable
”h]”h-)�”}”(hŒomodule-level variables created via *globals ()* can only be retrieved by *globals ()*, not as a normal variable”h]”(hŒ#module-level variables created via ”…”�”}”(hŒ#module-level variables created via ”hjD ubh8)�”}”(hŒ*globals ()*”h]”hŒ
globals ()”…”�”}”(hhhjM ubah}”(h ]”h"]”h$]”h&]”h(]”uh*h7hjD ubhŒ can only be retrieved by ”…”�”}”(hŒ can only be retrieved by ”hjD ubh8)�”}”(hŒ*globals ()*”h]”hŒ
globals ()”…”�”}”(hhhj` ubah}”(h ]”h"]”h$]”h&]”h(]”uh*h7hjD ubhŒ, not as a normal variable”…”�”}”(hŒ, not as a normal variable”hjD ubeh}”(h ]”h"]”h$]”h&]”h(]”uh*h,hh+hKªhj@ ubah}”(h ]”h"]”h$]”h&]”h(]”uh*j hj hhhh+hNubeh}”(h ]”h"]”h$]”h&]”h(]”Œbullet”Œ-”uh*j hh+hK©hj¿ hhubh-)�”}”(hŒFrom a different module:”h]”hŒFrom a different module:”…”�”}”(hj‰ hj‡ hhhNhNubah}”(h ]”h"]”h$]”h&]”h(]”uh*h,hh+hK¬hj¿ hhubj )�”}”(hhh]”(j )�”}”(hŒi*globals ()* can retrieve all module-level variables, wether created by *globals ()* or in the normal way”h]”h-)�”}”(hjš h]”(h8)�”}”(hŒ*globals ()*”h]”hŒ
globals ()”…”�”}”(hhhjŸ ubah}”(h ]”h"]”h$]”h&]”h(]”uh*h7hjœ ubhŒ< can retrieve all module-level variables, wether created by ”…”�”}”(hŒ< can retrieve all module-level variables, wether created by ”hjœ ubh8)�”}”(hŒ*globals ()*”h]”hŒ
globals ()”…”�”}”(hhhj² ubah}”(h ]”h"]”h$]”h&]”h(]”uh*h7hjœ ubhŒ or in the normal way”…”�”}”(hŒ or in the normal way”hjœ ubeh}”(h ]”h"]”h$]”h&]”h(]”uh*h,hh+hK®hj˜ ubah}”(h ]”h"]”h$]”h&]”h(]”uh*j hj• hhhh+hNubj )�”}”(hŒomodule-level variables created by *globals ()* can be retrieved by *globals ()*, but also as a normal variable
”h]”h-)�”}”(hŒnmodule-level variables created by *globals ()* can be retrieved by *globals ()*, but also as a normal variable”h]”(hŒ"module-level variables created by ”…”�”}”(hŒ"module-level variables created by ”hjÕ ubh8)�”}”(hŒ*globals ()*”h]”hŒ
globals ()”…”�”}”(hhhjÞ ubah}”(h ]”h"]”h$]”h&]”h(]”uh*h7hjÕ ubhŒ can be retrieved by ”…”�”}”(hŒ can be retrieved by ”hjÕ ubh8)�”}”(hŒ*globals ()*”h]”hŒ
globals ()”…”�”}”(hhhjñ ubah}”(h ]”h"]”h$]”h&]”h(]”uh*h7hjÕ ubhŒ, but also as a normal variable”…”�”}”(hŒ, but also as a normal variable”hjÕ ubeh}”(h ]”h"]”h$]”h&]”h(]”uh*h,hh+hK¯hjÑ ubah}”(h ]”h"]”h$]”h&]”h(]”uh*j hj• hhhh+hNubeh}”(h ]”h"]”h$]”h&]”h(]”j… j† uh*j hh+hK®hj¿ hhubh-)�”}”(hX Since imports are done (statically) at compile time, *from ... import \** will not include the variables created (dynamically) via *globals ()*.
You can however import the whole module, e.g. *import as * and then use *.*.”h]”(hŒ5Since imports are done (statically) at compile time, ”…”�”}”(hŒ5Since imports are done (statically) at compile time, ”hj hhhNhNubh8)�”}”(hŒ*from ... import \**”h]”hŒfrom … import *”…”�”}”(hhhj ubah}”(h ]”h"]”h$]”h&]”h(]”uh*h7hj ubhŒ: will not include the variables created (dynamically) via ”…”�”}”(hŒ: will not include the variables created (dynamically) via ”hj hhhNhNubh8)�”}”(hŒ*globals ()*”h]”hŒ
globals ()”…”�”}”(hhhj2 ubah}”(h ]”h"]”h$]”h&]”h(]”uh*h7hj ubhŒ0.
You can however import the whole module, e.g. ”…”�”}”(hŒ0.
You can however import the whole module, e.g. ”hj hhhNhNubh8)�”}”(hŒ"*import as *”h]”hŒ import as ”…”�”}”(hhhjE ubah}”(h ]”h"]”h$]”h&]”h(]”uh*h7hj ubhŒ and then use ”…”�”}”(hŒ and then use ”hj hhhNhNubh8)�”}”(hŒ**.*”h]”hŒ(.”…”�”}”(hhhjX ubah}”(h ]”h"]”h$]”h&]”h(]”uh*h7hj ubhŒ.”…”�”}”(hj÷ hj hhhNhNubeh}”(h ]”h"]”h$]”h&]”h(]”uh*h,hh+hK±hj¿ hhubh-)�”}”(hŒ%The code below shows what's possible:”h]”hŒ'The code below shows what’s possible:”…”�”}”(hjr hjp hhhNhNubah}”(h ]”h"]”h$]”h&]”h(]”uh*h,hh+hK´hj¿ hhubhf)�”}”(hhh]”(hk)�”}”(hŒ%Testlet: globals_function, module sub”h]”hŒ%Testlet: globals_function, module sub”…”�”}”(hjƒ hj� ubah}”(h ]”h"]”h$]”h&]”h(]”uh*hjhh+hK¶hj~ ubh{)�”}”(hXt # __pragma__ ('xglobs')
xxa = 'subXxa'
xxb = 'subXxb'
xxp = None
xxq = None
xxr = None
xxs = None
for name in ('xxp', 'xxq'):
globals () [name] = 'sub{}'.format (name.capitalize ())
def f ():
for name in ('xxr', 'xxs'):
globals () [name] = 'sub{}'.format (name.capitalize ())
def run (autoTester):
f ()
autoTester.check ('Check sub 1', xxa, xxb)
autoTester.check ('Check sub 2', * [globals () [name] for name in ('xxa', 'xxb', 'xxp', 'xxq', 'xxr', 'xxs')])
autoTester.check ('Check sub 3', * sorted ([value for key, value in globals () .items () if key.startswith ('xx')]))
”h]”hXt # __pragma__ ('xglobs')
xxa = 'subXxa'
xxb = 'subXxb'
xxp = None
xxq = None
xxr = None
xxs = None
for name in ('xxp', 'xxq'):
globals () [name] = 'sub{}'.format (name.capitalize ())
def f ():
for name in ('xxr', 'xxs'):
globals () [name] = 'sub{}'.format (name.capitalize ())
def run (autoTester):
f ()
autoTester.check ('Check sub 1', xxa, xxb)
autoTester.check ('Check sub 2', * [globals () [name] for name in ('xxa', 'xxb', 'xxp', 'xxq', 'xxr', 'xxs')])
autoTester.check ('Check sub 3', * sorted ([value for key, value in globals () .items () if key.startswith ('xx')]))
”…”�”}”(hhhj� ubah}”(h ]”h"]”h$]”h&]”h(]”Œsource”Œw/home/jac/active/geatec/transcrypt/Transcrypt/transcrypt/development/automated_tests/transcrypt/globals_function/sub.py”hŒh�hމh�}”h‘Ksuh*hzhh+hK¶hj~ ubeh}”(h ]”Œid22”ah"]”h–ah$]”h&]”h(]”Œ
literal_block”ˆuh*hehj¿ hhhhhNubhf)�”}”(hhh]”(hk)�”}”(hŒ'Testlet: globals_function, main program”h]”hŒ'Testlet: globals_function, main program”…”�”}”(hj hj« ubah}”(h ]”h"]”h$]”h&]”h(]”uh*hjhh+hKºhj¨ ubh{)�”}”(hXd # __pragma__ ('xglobs')
from globals_function import sub
xxa = 'mainXxa'
xxb = 'mainXxb'
xxp = None
xxq = None
xxr = None
xxs = None
for name in ('xxp', 'xxq'):
globals () [name] = 'main{}'.format (name.capitalize ())
def f ():
for name in ('xxr', 'xxs'):
globals () [name] = 'main{}'.format (name.capitalize ())
def run (autoTester):
f () # All vars of main added
sub.run (autoTester) # Shouldn't override vars of main
autoTester.check ('Check main 1', xxa, xxb)
autoTester.check ('Check main 2', * [globals () [name] for name in ('xxa', 'xxb', 'xxp', 'xxq', 'xxr', 'xxs')])
autoTester.check ('Check main 3', sub.xxa, sub.xxb, sub.xxp, sub.xxq, sub.xxr, sub.xxs)
autoTester.check ('Check main 4', * sorted ([value for key, value in globals () .items () if key.startswith ('xx')]))
”h]”hXd # __pragma__ ('xglobs')
from globals_function import sub
xxa = 'mainXxa'
xxb = 'mainXxb'
xxp = None
xxq = None
xxr = None
xxs = None
for name in ('xxp', 'xxq'):
globals () [name] = 'main{}'.format (name.capitalize ())
def f ():
for name in ('xxr', 'xxs'):
globals () [name] = 'main{}'.format (name.capitalize ())
def run (autoTester):
f () # All vars of main added
sub.run (autoTester) # Shouldn't override vars of main
autoTester.check ('Check main 1', xxa, xxb)
autoTester.check ('Check main 2', * [globals () [name] for name in ('xxa', 'xxb', 'xxp', 'xxq', 'xxr', 'xxs')])
autoTester.check ('Check main 3', sub.xxa, sub.xxb, sub.xxp, sub.xxq, sub.xxr, sub.xxs)
autoTester.check ('Check main 4', * sorted ([value for key, value in globals () .items () if key.startswith ('xx')]))
”…”�”}”(hhhj¹ ubah}”(h ]”h"]”h$]”h&]”h(]”Œsource”Œ|/home/jac/active/geatec/transcrypt/Transcrypt/transcrypt/development/automated_tests/transcrypt/globals_function/__init__.py”hŒh�hމh�}”h‘Ksuh*hzhh+hKºhj¨ ubeh}”(h ]”Œid23”ah"]”h–ah$]”h&]”h(]”Œ
literal_block”ˆuh*hehj¿ hhhhhNubh-)�”}”(hŒThe output will be:”h]”hŒThe output will be:”…”�”}”(hjÔ hjÒ hhhNhNubah}”(h ]”h"]”h$]”h&]”h(]”uh*h,hh+hK¾hj¿ hhubh Œfigure”“”)�”}”(hhh]”h Œimage”“”)�”}”(hŒh.. figure:: ../images/autotest_global_functions.png
:alt: Output of 'global_functions autotest'
”h]”h}”(h ]”h"]”h$]”h&]”h(]”Œalt”Œ%Output of 'global_functions autotest'”Œuri”Œ'../images/autotest_global_functions.png”Œ
candidates”}”Œ*”jô suh*jå hjâ hh+hNubah}”(h ]”h"]”h$]”h&]”h(]”uh*jà hj¿ hhhh+hNubeh}”(h ]”Œ5global-variable-access-by-using-globals-variable-name”ah"]”h$]”Œ]”ah&]”h(]”uh*h
hhhhhh+hK£ubh)�”}”(hhh]”(h)�”}”(hŒ0Indices and slices: LHS, RHS, basic and extended”h]”hŒ0Indices and slices: LHS, RHS, basic and extended”…”�”}”(hj hj hhhNhNubah}”(h ]”h"]”h$]”h&]”h(]”uh*hhj hhhh+hKÄubhf)�”}”(hhh]”(hk)�”}”(hŒTestlet: indices_and_slices”h]”hŒTestlet: indices_and_slices”…”�”}”(hj hj ubah}”(h ]”h"]”h$]”h&]”h(]”uh*hjhh+hKÆhj ubh{)�”}”(hX$ def run (autoTester):
# Right hand side slices
all = range (32)
autoTester.check (all)
autoTester.check (all [8 : 24])
autoTester.check (all [8 : 24 : 2])
# Left hand side slices
aList = [3, 4, 7, 8]
autoTester.check (aList)
aList [4 : 4] = [9, 10]
autoTester.check (aList)
aList [2 : 2] = [5, 6]
autoTester.check (aList)
aList [0 : 0] = [1, 2]
autoTester.check (aList)
aList [ : : 2] = [x + 0.001 for x in range (10) if x % 2]
autoTester.check (aList)
”h]”hX$ def run (autoTester):
# Right hand side slices
all = range (32)
autoTester.check (all)
autoTester.check (all [8 : 24])
autoTester.check (all [8 : 24 : 2])
# Left hand side slices
aList = [3, 4, 7, 8]
autoTester.check (aList)
aList [4 : 4] = [9, 10]
autoTester.check (aList)
aList [2 : 2] = [5, 6]
autoTester.check (aList)
aList [0 : 0] = [1, 2]
autoTester.check (aList)
aList [ : : 2] = [x + 0.001 for x in range (10) if x % 2]
autoTester.check (aList)
”…”�”}”(hhhj( ubah}”(h ]”h"]”h$]”h&]”h(]”Œsource”Œ~/home/jac/active/geatec/transcrypt/Transcrypt/transcrypt/development/automated_tests/transcrypt/indices_and_slices/__init__.py”hŒh�hމh�}”h‘Ksuh*hzhh+hKÆhj ubeh}”(h ]”Œid24”ah"]”h–ah$]”h&]”h(]”Œ
literal_block”ˆuh*hehj hhhhhNubeh}”(h ]”Œ-indices-and-slices-lhs-rhs-basic-and-extended”ah"]”h$]”Œ0indices and slices: lhs, rhs, basic and extended”ah&]”h(]”uh*h
hhhhhh+hKÄubh)�”}”(hhh]”(h)�”}”(hŒIterators and generators”h]”hŒIterators and generators”…”�”}”(hjN hjL hhhNhNubah}”(h ]”h"]”h$]”h&]”h(]”uh*hhjI hhhh+hKËubhf)�”}”(hhh]”(hk)�”}”(hŒ!Testlet: iterators_and_generators”h]”hŒ!Testlet: iterators_and_generators”…”�”}”(hj_ hj] ubah}”(h ]”h"]”h$]”h&]”h(]”uh*hjhh+hKÍhjZ ubh{)�”}”(hX¢ from org.transcrypt.stubs.browser import __pragma__
class Iterable:
def __init__ (self, i):
self.aList = range (0, 50, i)
def __iter__ (self):
return Iterator (self)
class Iterator:
def __init__ (self, iterable):
self.iterable = iterable
self.index = -1
def __next__ (self): # Should be auto-wrapped in a next (self) by the compiler
self.index += 1
if self.index > 5:
raise StopIteration ()
return self.iterable.aList [self.index]
def __iter__ (self):
return self
def exhaustableGenerator (i):
for i in range (5):
yield 2 * i
def run (autoTester):
exhaustableGenExp = (a * a * a for a in [10, 20, 30]) # Currently still converted to iterator on list comprehension, must also be iterable
# So becomes py_iter (aList).
# List already has an __iter__ which it will return, it's a __PyIterator__
# To that __PyIterator__, that will already have a __next__, py_iter first adds a next
# So exhaustableGenExp is an iterator with a next and a __next__
# If we call iter on that, py_iter is calle again py_iter, on an object with a next and a next __next__
# For this reason py_iter needs a recursion prevention check
iterables = [Iterable (7), exhaustableGenerator (5), [i * 3 for i in range (5)], exhaustableGenExp]
for iterable in iterables:
autoTester.check ('[1]')
iterator = iter (iterable)
try:
while True:
autoTester.check (next (iterator))
except Exception as exception:
autoTester.check (exception.__class__.__name__)
autoTester.check ('[2]')
iterator = iter (iterable)
try:
while True:
autoTester.check (next (iterator))
except Exception as exception:
autoTester.check (exception.__class__.__name__)
for iterable in iterables:
autoTester.check ('[3]')
for n in iterable:
autoTester.check (n)
autoTester.check ('[4]')
for n in iterable:
autoTester.check (n)
# BEGIN issue 196: for loop over iter (), runs OK but needs JavaScript 6. This should be clearly in the docs.
a = 0
vals = [1,2,3]
ret = iter (vals)
for m in ret:
a += m
autoTester.check (a)
# END issue 196
# BEGIN 1st example with 'send'
__pragma__ ('gsend')
def test0 ():
r = 0
while True:
r = r + (yield r)
gen0 = test0()
next (gen0)
autoTester.check (gen0.send (1))
autoTester.check (gen0.send (2))
def test1 ():
r = 0
while True:
r = (yield r) + r
gen1 = test1()
next (gen1)
autoTester.check (gen1.send (3))
autoTester.check (gen1.send (4))
# END 1st example with 'send'
def subGenerator ():
yield 27
yield 37
yield 47
def mainGenerator ():
yield 17
yield from subGenerator ()
yield 57
autoTester.check (* [i for i in mainGenerator ()])
def subCoroutine ():
autoTester.check (38)
yield
autoTester.check (48)
yield
autoTester.check (58)
yield
autoTester.check (68)
def mainCoroutine ():
autoTester.check (18)
yield
autoTester.check (28)
yield from subCoroutine ()
autoTester.check (78)
yield
autoTester.check (88)
m = mainCoroutine ()
for i in range (5):
m.send (None)
”h]”hX¢ from org.transcrypt.stubs.browser import __pragma__
class Iterable:
def __init__ (self, i):
self.aList = range (0, 50, i)
def __iter__ (self):
return Iterator (self)
class Iterator:
def __init__ (self, iterable):
self.iterable = iterable
self.index = -1
def __next__ (self): # Should be auto-wrapped in a next (self) by the compiler
self.index += 1
if self.index > 5:
raise StopIteration ()
return self.iterable.aList [self.index]
def __iter__ (self):
return self
def exhaustableGenerator (i):
for i in range (5):
yield 2 * i
def run (autoTester):
exhaustableGenExp = (a * a * a for a in [10, 20, 30]) # Currently still converted to iterator on list comprehension, must also be iterable
# So becomes py_iter (aList).
# List already has an __iter__ which it will return, it's a __PyIterator__
# To that __PyIterator__, that will already have a __next__, py_iter first adds a next
# So exhaustableGenExp is an iterator with a next and a __next__
# If we call iter on that, py_iter is calle again py_iter, on an object with a next and a next __next__
# For this reason py_iter needs a recursion prevention check
iterables = [Iterable (7), exhaustableGenerator (5), [i * 3 for i in range (5)], exhaustableGenExp]
for iterable in iterables:
autoTester.check ('[1]')
iterator = iter (iterable)
try:
while True:
autoTester.check (next (iterator))
except Exception as exception:
autoTester.check (exception.__class__.__name__)
autoTester.check ('[2]')
iterator = iter (iterable)
try:
while True:
autoTester.check (next (iterator))
except Exception as exception:
autoTester.check (exception.__class__.__name__)
for iterable in iterables:
autoTester.check ('[3]')
for n in iterable:
autoTester.check (n)
autoTester.check ('[4]')
for n in iterable:
autoTester.check (n)
# BEGIN issue 196: for loop over iter (), runs OK but needs JavaScript 6. This should be clearly in the docs.
a = 0
vals = [1,2,3]
ret = iter (vals)
for m in ret:
a += m
autoTester.check (a)
# END issue 196
# BEGIN 1st example with 'send'
__pragma__ ('gsend')
def test0 ():
r = 0
while True:
r = r + (yield r)
gen0 = test0()
next (gen0)
autoTester.check (gen0.send (1))
autoTester.check (gen0.send (2))
def test1 ():
r = 0
while True:
r = (yield r) + r
gen1 = test1()
next (gen1)
autoTester.check (gen1.send (3))
autoTester.check (gen1.send (4))
# END 1st example with 'send'
def subGenerator ():
yield 27
yield 37
yield 47
def mainGenerator ():
yield 17
yield from subGenerator ()
yield 57
autoTester.check (* [i for i in mainGenerator ()])
def subCoroutine ():
autoTester.check (38)
yield
autoTester.check (48)
yield
autoTester.check (58)
yield
autoTester.check (68)
def mainCoroutine ():
autoTester.check (18)
yield
autoTester.check (28)
yield from subCoroutine ()
autoTester.check (78)
yield
autoTester.check (88)
m = mainCoroutine ()
for i in range (5):
m.send (None)
”…”�”}”(hhhjk ubah}”(h ]”h"]”h$]”h&]”h(]”Œsource”Œ„/home/jac/active/geatec/transcrypt/Transcrypt/transcrypt/development/automated_tests/transcrypt/iterators_and_generators/__init__.py”hŒh�hމh�}”h‘Ksuh*hzhh+hKÍhjZ ubeh}”(h ]”Œid25”ah"]”h–ah$]”h&]”h(]”Œ
literal_block”ˆuh*hehjI hhhhhNubeh}”(h ]”Œiterators-and-generators”ah"]”h$]”Œiterators and generators”ah&]”h(]”uh*h
hhhhhh+hKËubh)�”}”(hhh]”(h)�”}”(hŒ'Lambda functions with all types of args”h]”hŒ'Lambda functions with all types of args”…”�”}”(hj‘ hj� hhhNhNubah}”(h ]”h"]”h$]”h&]”h(]”uh*hhjŒ hhhh+hKÒubhf)�”}”(hhh]”(hk)�”}”(hŒTestlet: lambda_functions”h]”hŒTestlet: lambda_functions”…”�”}”(hj¢ hj ubah}”(h ]”h"]”h$]”h&]”h(]”uh*hjhh+hKÔhj� ubh{)�”}”(hXë def run (autoTester):
z = 1000
autoTester.check ((lambda x, y: x + y + z) (111, 222))
def f (list0, list1, aFunc):
return [aFunc (*elem) for elem in zip (list0, list1)]
x = f (range (10), range (0, 100, 10), lambda x, y: x + y + z)
autoTester.check (x)
autoTester.check (f (range (10, 20), range (100, 200, 10), lambda x, y: x * y + 100 * z))
autoTester.check (f (range (10, 20), range (100, 200, 10), lambda *args: args [0] * args [1] + 100 * z))
”h]”hXë def run (autoTester):
z = 1000
autoTester.check ((lambda x, y: x + y + z) (111, 222))
def f (list0, list1, aFunc):
return [aFunc (*elem) for elem in zip (list0, list1)]
x = f (range (10), range (0, 100, 10), lambda x, y: x + y + z)
autoTester.check (x)
autoTester.check (f (range (10, 20), range (100, 200, 10), lambda x, y: x * y + 100 * z))
autoTester.check (f (range (10, 20), range (100, 200, 10), lambda *args: args [0] * args [1] + 100 * z))
”…”�”}”(hhhj® ubah}”(h ]”h"]”h$]”h&]”h(]”Œsource”Œ|/home/jac/active/geatec/transcrypt/Transcrypt/transcrypt/development/automated_tests/transcrypt/lambda_functions/__init__.py”hŒh�hމh�}”h‘Ksuh*hzhh+hKÔhj� ubeh}”(h ]”Œid26”ah"]”h–ah$]”h&]”h(]”Œ
literal_block”ˆuh*hehjŒ hhhhhNubeh}”(h ]”Œ'lambda-functions-with-all-types-of-args”ah"]”h$]”Œ'lambda functions with all types of args”ah&]”h(]”uh*h
hhhhhh+hKÒubh)�”}”(hhh]”(h)�”}”(hŒ=List comprehensions: multi-loop and nested with multiple if's”h]”hŒ?List comprehensions: multi-loop and nested with multiple if’s”…”�”}”(hjÔ hjÒ hhhNhNubah}”(h ]”h"]”h$]”h&]”h(]”uh*hhjÏ hhhh+hKÙubhf)�”}”(hhh]”(hk)�”}”(hŒTestlet: list_comprehensions”h]”hŒTestlet: list_comprehensions”…”�”}”(hjå hjã ubah}”(h ]”h"]”h$]”h&]”h(]”uh*hjhh+hKÛhjà ubh{)�”}”(hX´ def run (autoTester):
squares = [i * i for i in range (10) if i % 2]
autoTester.check (squares)
tuples = [
(x, y, z)
for x in (100, 200, 300, 400, 500, 600, 700)
for y in (10, 20, 30, 40, 50, 60, 70) if 20 < y < 60
for z in (1, 2, 3, 4, 5, 6, 7) if 200 < x < 600 if 2 < z < 6
]
autoTester.check (tuples)
tricky = [(2 * x, 3 * y) for x, y in ((10, 11), (20, 21))]
autoTester.check (tricky)
nested = [2 * x for x in [x * x for x in range (3)]]
autoTester.check (nested)
a = 100
x = 5
scopeTest = [x + a for x in range (5)]
autoTester.check (x)
autoTester.check (scopeTest)
”h]”hX´ def run (autoTester):
squares = [i * i for i in range (10) if i % 2]
autoTester.check (squares)
tuples = [
(x, y, z)
for x in (100, 200, 300, 400, 500, 600, 700)
for y in (10, 20, 30, 40, 50, 60, 70) if 20 < y < 60
for z in (1, 2, 3, 4, 5, 6, 7) if 200 < x < 600 if 2 < z < 6
]
autoTester.check (tuples)
tricky = [(2 * x, 3 * y) for x, y in ((10, 11), (20, 21))]
autoTester.check (tricky)
nested = [2 * x for x in [x * x for x in range (3)]]
autoTester.check (nested)
a = 100
x = 5
scopeTest = [x + a for x in range (5)]
autoTester.check (x)
autoTester.check (scopeTest)
”…”�”}”(hhhjñ ubah}”(h ]”h"]”h$]”h&]”h(]”Œsource”Œ/home/jac/active/geatec/transcrypt/Transcrypt/transcrypt/development/automated_tests/transcrypt/list_comprehensions/__init__.py”hŒh�hމh�}”h‘Ksuh*hzhh+hKÛhjà ubeh}”(h ]”Œid27”ah"]”h–ah$]”h&]”h(]”Œ
literal_block”ˆuh*hehjÏ hhhhhNubeh}”(h ]”Œ