Skip to content

Commit ead403a

Browse files
authored
Merge pull request #876 from TranscryptOrg/dev_3.9.3
Merge v3.9.3 updates to master Changelog: Added missing copysign and isclose functions to the math module (Issue 867) Updated the map function to allow for multiple iterators (Issue 862) Add key and default keyword arg support for min and max functions (Issue 305) Added string support for min and max functions (Issue 829) Added the copy module with copy and deepcopy functions (Issue 313) Fixed the disappearing kwargs issue for sort and sorted functions (Issue 687) Fixed the issue with sort and sorted functions that caused a string sort with number values (Issues 605 and 679) Fixed the issue with the sorted function that caused the original value to be modified (Issue 866) Added a bunch more autotests
2 parents a1bb81b + 1f46b5f commit ead403a

File tree

15 files changed

+339
-131
lines changed

15 files changed

+339
-131
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def read (*paths):
1010

1111
setup (
1212
name = 'Transcrypt',
13-
version = '3.9.2',
13+
version = '3.9.3',
1414
description = 'Python to JavaScript transpiler, supporting multiple inheritance and generating lean, highly readable code',
1515
long_description = (
1616
read ('README.rst')

transcrypt/development/automated_tests/transcrypt/autotest.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
if __pragma__ ('defined', 'undefined'):
3939
import module_collections
4040

41+
import module_copy
4142
import module_datetime
4243
import module_itertools
4344
import module_math
@@ -56,6 +57,7 @@
5657

5758
import truthyness
5859
import tuple_assignment
60+
import transducers
5961

6062
autoTester = org.transcrypt.autotester.AutoTester ()
6163
autoTester.run (arguments, 'arguments')
@@ -95,6 +97,7 @@
9597
if __pragma__ ('defined', 'undefined'):
9698
autoTester.run (module_collections, 'module_collections')
9799

100+
autoTester.run (module_copy, 'module_copy')
98101
autoTester.run (module_datetime, 'module_datetime')
99102
autoTester.run (module_itertools, 'module_itertools')
100103
autoTester.run (module_math, 'module_math')
@@ -113,5 +116,6 @@
113116

114117
autoTester.run (truthyness, 'truthyness')
115118
autoTester.run (tuple_assignment, 'tuple_assignment')
119+
autoTester.run (transducers, 'transducers')
116120

117121
autoTester.done ()

transcrypt/development/automated_tests/transcrypt/dictionaries/__init__.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ def run (autoTester):
8989
autoTester.check (tel.pop ('foo', None))
9090

9191
# Check compound keys (issue 281)
92-
9392
d = {}
9493
d ['a'] = 3777
9594
d [(1, 2)] = 4777
@@ -101,7 +100,16 @@ def run (autoTester):
101100
d [(1, 2)] = 4777
102101
autoTester.check (d ['a'], d [(1, 2)])
103102
__pragma__ ('noopov')
104-
103+
104+
# Check dict.popitem (issue 306)
105+
dict_306 = {'Abraham': 'Lincoln', 'Barack': 'O\'Bama', 'Thomas': 'Jefferson'}
106+
results = []
107+
try:
108+
while True:
109+
results.append (list(dict_306.popitem ()))
110+
except Exception as exception:
111+
autoTester.check (sorted (results))
112+
105113
# Check exceptions
106114
knights = {'robin': 'the brave', 'gallahad': 'the pure'}
107115
autoTester.check (

transcrypt/development/automated_tests/transcrypt/div_issues/__init__.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -264,16 +264,6 @@ def filter_word (word0, word1):
264264
autoTester.check (filter_word ('_in_', 'kind'))
265265
autoTester.check (filter_word ('min_', 'kind'))
266266

267-
autoTester.check ('Issue 306')
268-
dict_306 = {'Abraham': 'Lincoln', 'Barack': 'O\'Bama', 'Thomas': 'Jefferson'}
269-
results = []
270-
try:
271-
while True:
272-
results.append (dict_306.popitem ())
273-
except Exception as exception:
274-
autoTester.check (sorted (results))
275-
autoTester.check ('That\'s it')
276-
277267
autoTester.check ('Issue 314')
278268
try:
279269
autoTester.check (int (float (123)))

transcrypt/development/automated_tests/transcrypt/div_pulls/__init__.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@ def run (autoTester):
4040
autoTester.check (s [2:])
4141
autoTester.check (s [::2])
4242

43-
autoTester.check ('Pull 59')
44-
autoTester.check (list (filter (lambda x: x % 2 == 0, range (10))))
45-
autoTester.check (list (map (lambda x: x*x, range (0, 31, 3))))
46-
4743
autoTester.check ('Pull 561')
4844
def brackets (word):
4945
autoTester.check ('sideeffect')

transcrypt/development/automated_tests/transcrypt/general_functions/__init__.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,36 @@ def run (autoTester):
3535
autoTester.check (len (collection))
3636

3737
autoTester.check ('sort and sorted<br>')
38-
a = [1, 5, 3, 2, -1]
38+
a = [11, 7, 23, 4, -1]
3939
b = ['sun', 'earth', 'moon']
40-
40+
c = [{'name': 'Defg', 'qty': 99}, {'name': 'Abcd', 'qty': 42}, {'name': 'Hijk', 'qty': 11}]
41+
d = [[21, 19, 54], [22, 7, 12, 37]]
42+
43+
autoTester.check (a)
4144
autoTester.check (sorted (a))
45+
autoTester.check (a)
46+
autoTester.check (sorted (a, key=str))
47+
autoTester.check (sorted (a, key=int))
4248
autoTester.check (sorted (b))
43-
49+
50+
autoTester.check (sorted(c, key=lambda k: k['qty']))
51+
autoTester.check (sorted(c, key=lambda k: k['name']))
52+
autoTester.check (sorted(c, key=lambda k: k['name'], reverse=True))
53+
54+
autoTester.check (sorted(d))
55+
autoTester.check (sorted(d, key=sum))
56+
57+
# Make sure sorted is doing a proper shallow copy (issue 866)
58+
e = sorted(d)
59+
autoTester.check(e)
60+
d[1][1] = 9
61+
autoTester.check(d)
62+
autoTester.check(e)
63+
d[1] = [22,14,36]
64+
autoTester.check(d)
65+
autoTester.check(e)
66+
67+
4468
a.sort ()
4569
autoTester.check (a)
4670

@@ -53,6 +77,9 @@ def run (autoTester):
5377
a.sort (reverse = True)
5478
autoTester.check (a)
5579

80+
a.sort (key=int)
81+
autoTester.check (a)
82+
5683
b.sort (reverse = True)
5784
autoTester.check (b)
5885

transcrypt/development/automated_tests/transcrypt/module_builtin/__init__.py

Lines changed: 96 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,41 @@ def canonizeStringList (stringList):
1212
return [canonizeString (aString) for aString in stringList]
1313

1414
def run (autoTester):
15-
autoTester.check ('min', min (-1.1, -1, -3))
16-
autoTester.check ('max', max (-1.1, -1, -3))
15+
autoTester.check ('min',
16+
min (-1.1, -1, -3),
17+
min ([-1.1, -1, -3]),
18+
min ((-1.1, -1, -3)),
19+
min ('abc', 'ABC', 'xyz', 'XYZ'),
20+
min ('abc', 'ABC', 'xyz', 'XYZ', key=lambda v: v[1]),
21+
min (['abc', 'ABC', 'xyz', 'XYZ']),
22+
min([5,6,7,8,9],[1,2,3,4],key=len),
23+
min([[5,6,7,8,9],[1,2,3,4]],default=[1,1,1],key=len),
24+
min ([], default='zzz'),
25+
)
26+
27+
autoTester.check ('max',
28+
max (-1.1, -1, -3),
29+
max ([-1.1, -1, -3]),
30+
max ((-1.1, -1, -3)),
31+
max ('abc', 'ABC', 'xyz', 'XYZ'),
32+
max ('abc', 'ABC', 'xyz', 'XYZ', key=lambda v: v[1]),
33+
max (['abc', 'ABC', 'xyz', 'XYZ']),
34+
max([5,6,7,8,9],[1,2,3,4],key=len),
35+
max([[5,6,7,8,9],[1,2,3,4]],default=[1,1,1],key=len),
36+
max ([], default='zzz'),
37+
)
38+
# autoTester.check ('max', autoTester.expectException(lambda: max () ))
39+
# autoTester.check ('max', autoTester.expectException(lambda: max (1,2,3,4, default=5) ))
40+
# autoTester.check ('max', autoTester.expectException(lambda: max (default=5)))
41+
# autoTester.check ('max', autoTester.expectException(lambda: max ([])))
42+
# autoTester.check ('max', autoTester.expectException(lambda: max([5,6,7,8,9],[1,2,3,4],default=[1,1,1],key=len) ))
43+
# autoTester.check ('max', autoTester.expectException(lambda: max ([4, 5, 'xyz', 'XYZ']) ))
44+
1745
autoTester.check ('abs', abs (-1), abs (1), abs (0), abs (-0.1), abs (0.1))
46+
1847
autoTester.check ('ord', ord ('a'), ord ('e´'[0])) # This is the 2 codepoint version
19-
48+
autoTester.check ('chr', chr (97), chr (122), chr (65), chr (90)) # a z A Z
49+
2050
autoTester.check ('round',
2151
round (4.006),
2252
round (4.006, 2),
@@ -104,63 +134,75 @@ def run (autoTester):
104134
'<br>'
105135
)
106136

107-
autoTester.check("".isalpha())
108-
autoTester.check("123".isalpha())
109-
autoTester.check("abc".isalpha())
110-
autoTester.check("abc123".isalpha())
137+
autoTester.check("isalpha",
138+
"".isalpha(),
139+
"123".isalpha(),
140+
"abc".isalpha(),
141+
"abc123".isalpha(),
142+
)
111143

112144
enumerate_list = ['a', 'b', 'c', 'd', 'e']
113145
# JS does not have tuples so coerce to list of lists
114-
autoTester.check([list(item) for item in enumerate(enumerate_list)])
115-
autoTester.check([list(item) for item in enumerate(enumerate_list, 1)])
116-
autoTester.check([list(item) for item in enumerate(enumerate_list, start=2)])
146+
autoTester.check("enumerate",
147+
[list(item) for item in enumerate(enumerate_list)],
148+
[list(item) for item in enumerate(enumerate_list, 1)],
149+
[list(item) for item in enumerate(enumerate_list, start=2)]
150+
)
117151

118152
replace_test = "abcabcabcabc"
119-
autoTester.check(replace_test.replace("c", "x"))
120-
autoTester.check(replace_test.replace("c", "x", -1))
121-
autoTester.check(replace_test.replace("c", "x", 0))
122-
autoTester.check(replace_test.replace("c", "x", 1))
123-
autoTester.check(replace_test.replace("c", "x", 2))
124-
autoTester.check(replace_test.replace("c", "x", 10))
153+
autoTester.check("replace",
154+
replace_test.replace("c", "x"),
155+
replace_test.replace("c", "x", -1),
156+
replace_test.replace("c", "x", 0),
157+
replace_test.replace("c", "x", 1),
158+
replace_test.replace("c", "x", 2),
159+
replace_test.replace("c", "x", 10),
160+
)
125161

126-
autoTester.check(bin(42))
127-
autoTester.check(oct(42))
128-
autoTester.check(hex(42))
129-
autoTester.check(bin(0))
130-
autoTester.check(oct(0))
131-
autoTester.check(hex(0))
132-
autoTester.check(bin(-42))
133-
autoTester.check(oct(-42))
134-
autoTester.check(hex(-42))
162+
autoTester.check("bin-oct-hex",
163+
bin(42),
164+
oct(42),
165+
hex(42),
166+
bin(0),
167+
oct(0),
168+
hex(0),
169+
bin(-42),
170+
oct(-42),
171+
hex(-42),
172+
)
135173

136174
string_test = "abcdefghijkl"
137-
autoTester.check(string_test.startswith(""))
138-
autoTester.check(string_test.startswith("abcd"))
139-
autoTester.check(string_test.startswith("efgh"))
140-
autoTester.check(string_test.startswith("efgh", 2))
141-
autoTester.check(string_test.startswith("efgh", 4))
142-
autoTester.check(string_test.startswith("abcd", 0, 3))
143-
autoTester.check(string_test.startswith("abcd", 0, 5))
144-
autoTester.check(string_test.startswith("efgh", 4, -2))
145-
autoTester.check(string_test.startswith("efgh", 4, -6))
146-
autoTester.check(string_test.startswith(("abc",)))
147-
autoTester.check(string_test.startswith(("abc", "de", "gh")))
148-
autoTester.check(string_test.startswith(("abc", "de", "gh"), 2))
149-
autoTester.check(string_test.startswith(("abc", "de", "gh"), 3))
150-
autoTester.check(string_test.startswith(("abc", "defgh"), 3, 9))
151-
autoTester.check(string_test.startswith(("abc", "defgh"), 3, 6))
175+
autoTester.check("startswith",
176+
string_test.startswith(""),
177+
string_test.startswith("abcd"),
178+
string_test.startswith("efgh"),
179+
string_test.startswith("efgh", 2),
180+
string_test.startswith("efgh", 4),
181+
string_test.startswith("abcd", 0, 3),
182+
string_test.startswith("abcd", 0, 5),
183+
string_test.startswith("efgh", 4, -2),
184+
string_test.startswith("efgh", 4, -6),
185+
string_test.startswith(("abc",)),
186+
string_test.startswith(("abc", "de", "gh")),
187+
string_test.startswith(("abc", "de", "gh"), 2),
188+
string_test.startswith(("abc", "de", "gh"), 3),
189+
string_test.startswith(("abc", "defgh"), 3, 9),
190+
string_test.startswith(("abc", "defgh"), 3, 6),
191+
)
152192

153-
autoTester.check(string_test.endswith(""))
154-
autoTester.check(string_test.endswith("ijkl"))
155-
autoTester.check(string_test.endswith("efgh"))
156-
autoTester.check(string_test.endswith("efgh", 2))
157-
autoTester.check(string_test.endswith("abcd", 0, 3))
158-
autoTester.check(string_test.endswith("abcd", 0, 4))
159-
autoTester.check(string_test.endswith("efgh", 4, -2))
160-
autoTester.check(string_test.endswith("efgh", 4, -4))
161-
autoTester.check(string_test.endswith(("ijkl",)))
162-
autoTester.check(string_test.endswith(("abc", "de", "gh")))
163-
autoTester.check(string_test.endswith(("abc", "de", "gh"), 3, -4))
164-
autoTester.check(string_test.endswith(("abc", "de", "gh"), -6, -4))
165-
autoTester.check(string_test.endswith(("abc", "defgh"), -3, 8))
166-
autoTester.check(string_test.endswith(("abc", "defgh"), -9, 8))
193+
autoTester.check("endswith",
194+
string_test.endswith(""),
195+
string_test.endswith("ijkl"),
196+
string_test.endswith("efgh"),
197+
string_test.endswith("efgh", 2),
198+
string_test.endswith("abcd", 0, 3),
199+
string_test.endswith("abcd", 0, 4),
200+
string_test.endswith("efgh", 4, -2),
201+
string_test.endswith("efgh", 4, -4),
202+
string_test.endswith(("ijkl",)),
203+
string_test.endswith(("abc", "de", "gh")),
204+
string_test.endswith(("abc", "de", "gh"), 3, -4),
205+
string_test.endswith(("abc", "de", "gh"), -6, -4),
206+
string_test.endswith(("abc", "defgh"), -3, 8),
207+
string_test.endswith(("abc", "defgh"), -9, 8),
208+
)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import copy
2+
3+
def run (autoTester):
4+
a = {'a': 1, 'b': 2, 'c': 3}
5+
b = copy.copy(a)
6+
c = [[1,2,3],[4,5,6]]
7+
d = copy.copy(c)
8+
e = copy.deepcopy(c)
9+
10+
autoTester.check ('copy')
11+
autoTester.check (b)
12+
autoTester.check (a)
13+
a['b'] = 9
14+
autoTester.check (a)
15+
autoTester.check (b)
16+
17+
autoTester.check ('deepcopy')
18+
autoTester.check (d)
19+
autoTester.check (e)
20+
c[1][1] = 9
21+
autoTester.check (c)
22+
autoTester.check (d)
23+
autoTester.check (e)

transcrypt/development/automated_tests/transcrypt/module_math/__init__.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,31 @@ def run (autoTester):
5050
check (floor (3.5))
5151
check (ceil (3.5))
5252
check (trunc (3.5))
53-
54-
check (isnan (3))
55-
check (isnan (nan))
53+
54+
# Format float since python adds .0 and JS does not
55+
autoTester.check('{0:g}'.format(copysign(42.0, 99.0)))
56+
autoTester.check('{0:g}'.format(copysign(-42, 99.0)))
57+
autoTester.check('{0:g}'.format(copysign(42, -99.0)))
58+
autoTester.check('{0:g}'.format(copysign(-42.0, -99.0)))
59+
60+
autoTester.check(
61+
isclose(2.123456, 2.123457),
62+
isclose(2.12, 2.123457),
63+
isclose(2.1234567891, 2.1234567892),
64+
isclose(2.1, 2, rel_tol=0.05),
65+
isclose(2.15, 2, rel_tol=0.05),
66+
isclose(1, 1),
67+
isclose(1, 1.000000002),
68+
isclose(1, 1.0000000002),
69+
isclose(1.0, 1.02, rel_tol=0.02),
70+
isclose(1.0, 1.02, rel_tol=0.0, abs_tol=0.02),
71+
isclose(0.000000001, 0.0, rel_tol=0.000000001),
72+
isclose(0.000000001, 0.0, rel_tol=0.0, abs_tol=0.000000000999),
73+
isclose(0.000000001, 0.0, rel_tol=0.0, abs_tol=0.000000001),
74+
isclose(0.0, 0.000000001, rel_tol=0.0, abs_tol=0.000000001),
75+
)
76+
77+
autoTester.check (isnan (3))
78+
autoTester.check (isnan (nan))
5679

5780

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
def run (autoTester):
3+
autoTester.check ('filter',
4+
list (filter (lambda x: x % 2 == 0, range (10))),
5+
)
6+
7+
autoTester.check ('map',
8+
list (map (lambda x: x* x, range(0, 31, 3))),
9+
list (map (lambda x, y: x * y, range(0, 31, 3), [1, 2, 3])),
10+
list (map (lambda x, y, z: x * y + z, range(0, 31, 3), [1, 2, 3, 4], (2, 4, 6))),
11+
)

0 commit comments

Comments
 (0)