Skip to content

Commit

Permalink
Merge pull request #876 from TranscryptOrg/dev_3.9.3
Browse files Browse the repository at this point in the history
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
  • Loading branch information
JennaSys authored Jul 17, 2024
2 parents a1bb81b + 1f46b5f commit ead403a
Show file tree
Hide file tree
Showing 15 changed files with 339 additions and 131 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def read (*paths):

setup (
name = 'Transcrypt',
version = '3.9.2',
version = '3.9.3',
description = 'Python to JavaScript transpiler, supporting multiple inheritance and generating lean, highly readable code',
long_description = (
read ('README.rst')
Expand Down
4 changes: 4 additions & 0 deletions transcrypt/development/automated_tests/transcrypt/autotest.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
if __pragma__ ('defined', 'undefined'):
import module_collections

import module_copy
import module_datetime
import module_itertools
import module_math
Expand All @@ -56,6 +57,7 @@

import truthyness
import tuple_assignment
import transducers

autoTester = org.transcrypt.autotester.AutoTester ()
autoTester.run (arguments, 'arguments')
Expand Down Expand Up @@ -95,6 +97,7 @@
if __pragma__ ('defined', 'undefined'):
autoTester.run (module_collections, 'module_collections')

autoTester.run (module_copy, 'module_copy')
autoTester.run (module_datetime, 'module_datetime')
autoTester.run (module_itertools, 'module_itertools')
autoTester.run (module_math, 'module_math')
Expand All @@ -113,5 +116,6 @@

autoTester.run (truthyness, 'truthyness')
autoTester.run (tuple_assignment, 'tuple_assignment')
autoTester.run (transducers, 'transducers')

autoTester.done ()
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ def run (autoTester):
autoTester.check (tel.pop ('foo', None))

# Check compound keys (issue 281)

d = {}
d ['a'] = 3777
d [(1, 2)] = 4777
Expand All @@ -101,7 +100,16 @@ def run (autoTester):
d [(1, 2)] = 4777
autoTester.check (d ['a'], d [(1, 2)])
__pragma__ ('noopov')


# Check dict.popitem (issue 306)
dict_306 = {'Abraham': 'Lincoln', 'Barack': 'O\'Bama', 'Thomas': 'Jefferson'}
results = []
try:
while True:
results.append (list(dict_306.popitem ()))
except Exception as exception:
autoTester.check (sorted (results))

# Check exceptions
knights = {'robin': 'the brave', 'gallahad': 'the pure'}
autoTester.check (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,16 +264,6 @@ def filter_word (word0, word1):
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)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ def run (autoTester):
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')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,36 @@ def run (autoTester):
autoTester.check (len (collection))

autoTester.check ('sort and sorted<br>')
a = [1, 5, 3, 2, -1]
a = [11, 7, 23, 4, -1]
b = ['sun', 'earth', 'moon']

c = [{'name': 'Defg', 'qty': 99}, {'name': 'Abcd', 'qty': 42}, {'name': 'Hijk', 'qty': 11}]
d = [[21, 19, 54], [22, 7, 12, 37]]

autoTester.check (a)
autoTester.check (sorted (a))
autoTester.check (a)
autoTester.check (sorted (a, key=str))
autoTester.check (sorted (a, key=int))
autoTester.check (sorted (b))


autoTester.check (sorted(c, key=lambda k: k['qty']))
autoTester.check (sorted(c, key=lambda k: k['name']))
autoTester.check (sorted(c, key=lambda k: k['name'], reverse=True))

autoTester.check (sorted(d))
autoTester.check (sorted(d, key=sum))

# Make sure sorted is doing a proper shallow copy (issue 866)
e = sorted(d)
autoTester.check(e)
d[1][1] = 9
autoTester.check(d)
autoTester.check(e)
d[1] = [22,14,36]
autoTester.check(d)
autoTester.check(e)


a.sort ()
autoTester.check (a)

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

a.sort (key=int)
autoTester.check (a)

b.sort (reverse = True)
autoTester.check (b)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,41 @@ def canonizeStringList (stringList):
return [canonizeString (aString) for aString in stringList]

def run (autoTester):
autoTester.check ('min', min (-1.1, -1, -3))
autoTester.check ('max', max (-1.1, -1, -3))
autoTester.check ('min',
min (-1.1, -1, -3),
min ([-1.1, -1, -3]),
min ((-1.1, -1, -3)),
min ('abc', 'ABC', 'xyz', 'XYZ'),
min ('abc', 'ABC', 'xyz', 'XYZ', key=lambda v: v[1]),
min (['abc', 'ABC', 'xyz', 'XYZ']),
min([5,6,7,8,9],[1,2,3,4],key=len),
min([[5,6,7,8,9],[1,2,3,4]],default=[1,1,1],key=len),
min ([], default='zzz'),
)

autoTester.check ('max',
max (-1.1, -1, -3),
max ([-1.1, -1, -3]),
max ((-1.1, -1, -3)),
max ('abc', 'ABC', 'xyz', 'XYZ'),
max ('abc', 'ABC', 'xyz', 'XYZ', key=lambda v: v[1]),
max (['abc', 'ABC', 'xyz', 'XYZ']),
max([5,6,7,8,9],[1,2,3,4],key=len),
max([[5,6,7,8,9],[1,2,3,4]],default=[1,1,1],key=len),
max ([], default='zzz'),
)
# autoTester.check ('max', autoTester.expectException(lambda: max () ))
# autoTester.check ('max', autoTester.expectException(lambda: max (1,2,3,4, default=5) ))
# autoTester.check ('max', autoTester.expectException(lambda: max (default=5)))
# autoTester.check ('max', autoTester.expectException(lambda: max ([])))
# autoTester.check ('max', autoTester.expectException(lambda: max([5,6,7,8,9],[1,2,3,4],default=[1,1,1],key=len) ))
# autoTester.check ('max', autoTester.expectException(lambda: max ([4, 5, 'xyz', 'XYZ']) ))

autoTester.check ('abs', abs (-1), abs (1), abs (0), abs (-0.1), abs (0.1))

autoTester.check ('ord', ord ('a'), ord ('e´'[0])) # This is the 2 codepoint version

autoTester.check ('chr', chr (97), chr (122), chr (65), chr (90)) # a z A Z

autoTester.check ('round',
round (4.006),
round (4.006, 2),
Expand Down Expand Up @@ -104,63 +134,75 @@ def run (autoTester):
'<br>'
)

autoTester.check("".isalpha())
autoTester.check("123".isalpha())
autoTester.check("abc".isalpha())
autoTester.check("abc123".isalpha())
autoTester.check("isalpha",
"".isalpha(),
"123".isalpha(),
"abc".isalpha(),
"abc123".isalpha(),
)

enumerate_list = ['a', 'b', 'c', 'd', 'e']
# JS does not have tuples so coerce to list of lists
autoTester.check([list(item) for item in enumerate(enumerate_list)])
autoTester.check([list(item) for item in enumerate(enumerate_list, 1)])
autoTester.check([list(item) for item in enumerate(enumerate_list, start=2)])
autoTester.check("enumerate",
[list(item) for item in enumerate(enumerate_list)],
[list(item) for item in enumerate(enumerate_list, 1)],
[list(item) for item in enumerate(enumerate_list, start=2)]
)

replace_test = "abcabcabcabc"
autoTester.check(replace_test.replace("c", "x"))
autoTester.check(replace_test.replace("c", "x", -1))
autoTester.check(replace_test.replace("c", "x", 0))
autoTester.check(replace_test.replace("c", "x", 1))
autoTester.check(replace_test.replace("c", "x", 2))
autoTester.check(replace_test.replace("c", "x", 10))
autoTester.check("replace",
replace_test.replace("c", "x"),
replace_test.replace("c", "x", -1),
replace_test.replace("c", "x", 0),
replace_test.replace("c", "x", 1),
replace_test.replace("c", "x", 2),
replace_test.replace("c", "x", 10),
)

autoTester.check(bin(42))
autoTester.check(oct(42))
autoTester.check(hex(42))
autoTester.check(bin(0))
autoTester.check(oct(0))
autoTester.check(hex(0))
autoTester.check(bin(-42))
autoTester.check(oct(-42))
autoTester.check(hex(-42))
autoTester.check("bin-oct-hex",
bin(42),
oct(42),
hex(42),
bin(0),
oct(0),
hex(0),
bin(-42),
oct(-42),
hex(-42),
)

string_test = "abcdefghijkl"
autoTester.check(string_test.startswith(""))
autoTester.check(string_test.startswith("abcd"))
autoTester.check(string_test.startswith("efgh"))
autoTester.check(string_test.startswith("efgh", 2))
autoTester.check(string_test.startswith("efgh", 4))
autoTester.check(string_test.startswith("abcd", 0, 3))
autoTester.check(string_test.startswith("abcd", 0, 5))
autoTester.check(string_test.startswith("efgh", 4, -2))
autoTester.check(string_test.startswith("efgh", 4, -6))
autoTester.check(string_test.startswith(("abc",)))
autoTester.check(string_test.startswith(("abc", "de", "gh")))
autoTester.check(string_test.startswith(("abc", "de", "gh"), 2))
autoTester.check(string_test.startswith(("abc", "de", "gh"), 3))
autoTester.check(string_test.startswith(("abc", "defgh"), 3, 9))
autoTester.check(string_test.startswith(("abc", "defgh"), 3, 6))
autoTester.check("startswith",
string_test.startswith(""),
string_test.startswith("abcd"),
string_test.startswith("efgh"),
string_test.startswith("efgh", 2),
string_test.startswith("efgh", 4),
string_test.startswith("abcd", 0, 3),
string_test.startswith("abcd", 0, 5),
string_test.startswith("efgh", 4, -2),
string_test.startswith("efgh", 4, -6),
string_test.startswith(("abc",)),
string_test.startswith(("abc", "de", "gh")),
string_test.startswith(("abc", "de", "gh"), 2),
string_test.startswith(("abc", "de", "gh"), 3),
string_test.startswith(("abc", "defgh"), 3, 9),
string_test.startswith(("abc", "defgh"), 3, 6),
)

autoTester.check(string_test.endswith(""))
autoTester.check(string_test.endswith("ijkl"))
autoTester.check(string_test.endswith("efgh"))
autoTester.check(string_test.endswith("efgh", 2))
autoTester.check(string_test.endswith("abcd", 0, 3))
autoTester.check(string_test.endswith("abcd", 0, 4))
autoTester.check(string_test.endswith("efgh", 4, -2))
autoTester.check(string_test.endswith("efgh", 4, -4))
autoTester.check(string_test.endswith(("ijkl",)))
autoTester.check(string_test.endswith(("abc", "de", "gh")))
autoTester.check(string_test.endswith(("abc", "de", "gh"), 3, -4))
autoTester.check(string_test.endswith(("abc", "de", "gh"), -6, -4))
autoTester.check(string_test.endswith(("abc", "defgh"), -3, 8))
autoTester.check(string_test.endswith(("abc", "defgh"), -9, 8))
autoTester.check("endswith",
string_test.endswith(""),
string_test.endswith("ijkl"),
string_test.endswith("efgh"),
string_test.endswith("efgh", 2),
string_test.endswith("abcd", 0, 3),
string_test.endswith("abcd", 0, 4),
string_test.endswith("efgh", 4, -2),
string_test.endswith("efgh", 4, -4),
string_test.endswith(("ijkl",)),
string_test.endswith(("abc", "de", "gh")),
string_test.endswith(("abc", "de", "gh"), 3, -4),
string_test.endswith(("abc", "de", "gh"), -6, -4),
string_test.endswith(("abc", "defgh"), -3, 8),
string_test.endswith(("abc", "defgh"), -9, 8),
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import copy

def run (autoTester):
a = {'a': 1, 'b': 2, 'c': 3}
b = copy.copy(a)
c = [[1,2,3],[4,5,6]]
d = copy.copy(c)
e = copy.deepcopy(c)

autoTester.check ('copy')
autoTester.check (b)
autoTester.check (a)
a['b'] = 9
autoTester.check (a)
autoTester.check (b)

autoTester.check ('deepcopy')
autoTester.check (d)
autoTester.check (e)
c[1][1] = 9
autoTester.check (c)
autoTester.check (d)
autoTester.check (e)
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,31 @@ def run (autoTester):
check (floor (3.5))
check (ceil (3.5))
check (trunc (3.5))

check (isnan (3))
check (isnan (nan))

# Format float since python adds .0 and JS does not
autoTester.check('{0:g}'.format(copysign(42.0, 99.0)))
autoTester.check('{0:g}'.format(copysign(-42, 99.0)))
autoTester.check('{0:g}'.format(copysign(42, -99.0)))
autoTester.check('{0:g}'.format(copysign(-42.0, -99.0)))

autoTester.check(
isclose(2.123456, 2.123457),
isclose(2.12, 2.123457),
isclose(2.1234567891, 2.1234567892),
isclose(2.1, 2, rel_tol=0.05),
isclose(2.15, 2, rel_tol=0.05),
isclose(1, 1),
isclose(1, 1.000000002),
isclose(1, 1.0000000002),
isclose(1.0, 1.02, rel_tol=0.02),
isclose(1.0, 1.02, rel_tol=0.0, abs_tol=0.02),
isclose(0.000000001, 0.0, rel_tol=0.000000001),
isclose(0.000000001, 0.0, rel_tol=0.0, abs_tol=0.000000000999),
isclose(0.000000001, 0.0, rel_tol=0.0, abs_tol=0.000000001),
isclose(0.0, 0.000000001, rel_tol=0.0, abs_tol=0.000000001),
)

autoTester.check (isnan (3))
autoTester.check (isnan (nan))


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

def run (autoTester):
autoTester.check ('filter',
list (filter (lambda x: x % 2 == 0, range (10))),
)

autoTester.check ('map',
list (map (lambda x: x* x, range(0, 31, 3))),
list (map (lambda x, y: x * y, range(0, 31, 3), [1, 2, 3])),
list (map (lambda x, y, z: x * y + z, range(0, 31, 3), [1, 2, 3, 4], (2, 4, 6))),
)
Loading

0 comments on commit ead403a

Please sign in to comment.