Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable CPython's test_int.py in CI #2367

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion www/src/Lib/_testcapi.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import unittest

CHAR_MAX = 127

CHAR_MIN = -128
Expand Down Expand Up @@ -192,7 +194,7 @@ def raise_memoryerror(*args,**kw):
pass

def run_in_subinterp(*args,**kw):
pass
raise unittest.SkipTest("Brython does not support subinterpreters")

def set_exc_info(*args,**kw):
pass
Expand Down
18 changes: 10 additions & 8 deletions www/src/brython.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ var pylist=['VFS_import','__future__','_aio','_codecs','_codecs_jp','_collection
for(var i=0;i < pylist.length;i++){$B.stdlib[pylist[i]]=['py']}
var js=['_ajax','_ast','_base64','_binascii','_io_classes','_json','_jsre','_locale','_multiprocessing','_posixsubprocess','_profile','_random','_sre','_sre_utils','_string','_strptime','_svg','_symtable','_tokenize','_webcomponent','_webworker','_zlib_utils','aes','array','builtins','dis','encoding_cp932','hashlib','hmac-md5','hmac-ripemd160','hmac-sha1','hmac-sha224','hmac-sha256','hmac-sha3','hmac-sha384','hmac-sha512','html_parser','marshal','math','md5','modulefinder','pbkdf2','posix','pyexpat','python_re','rabbit','rabbit-legacy','rc4','ripemd160','sha1','sha224','sha256','sha3','sha384','sha512','tripledes','unicodedata','xml_helpers','xml_parser']
for(var i=0;i < js.length;i++){$B.stdlib[js[i]]=['js']}
var pkglist=['browser','browser.widgets','collections','concurrent','concurrent.futures','email','email.mime','encodings','html','http','importlib','importlib.metadata','importlib.resources','json','logging','multiprocessing','multiprocessing.dummy','pyexpat_utils','site-packages.foobar','site-packages.simpleaio','site-packages.ui','test','test.encoded_modules','test.leakers','test.namespace_pkgs.not_a_namespace_pkg.foo','test.support','test.test_email','test.test_importlib','test.test_importlib.builtin','test.test_importlib.extension','test.test_importlib.frozen','test.test_importlib.import_','test.test_importlib.source','test.test_json','test.tracedmodules','unittest','unittest.test','unittest.test.testmock','urllib']
var pkglist=['browser','browser.widgets','collections','concurrent','concurrent.futures','email','email.mime','encodings','html','http','importlib','importlib.metadata','importlib.resources','json','logging','multiprocessing','multiprocessing.dummy','site-packages.foobar','site-packages.simpleaio','site-packages.ui','test','test.encoded_modules','test.leakers','test.namespace_pkgs.not_a_namespace_pkg.foo','test.support','test.test_email','test.test_importlib','test.test_importlib.builtin','test.test_importlib.extension','test.test_importlib.frozen','test.test_importlib.import_','test.test_importlib.source','test.test_json','test.tracedmodules','unittest','unittest.test','unittest.test.testmock','urllib']
for(var i=0;i < pkglist.length;i++){$B.stdlib[pkglist[i]]=['py',true]}
$B.stdlib_module_names=Object.keys($B.stdlib)})(__BRYTHON__)
;
Expand All @@ -180,9 +180,9 @@ $B.unicode_bidi_whitespace=[9,10,11,12,13,28,29,30,31,32,133,5760,8192,8193,8194
;
__BRYTHON__.implementation=[3,12,5,'dev',0]
__BRYTHON__.version_info=[3,12,0,'final',0]
__BRYTHON__.compiled_date="2024-07-04 09:39:49.791767"
__BRYTHON__.timestamp=1720078789791
__BRYTHON__.builtin_module_names=["_ajax","_ast","_base64","_binascii","_io_classes","_json","_jsre","_locale","_multiprocessing","_posixsubprocess","_profile","_random","_sre","_sre_utils","_string","_strptime","_svg","_symtable","_tokenize","_webcomponent","_webworker","_zlib_utils","_zlib_utils1","_zlib_utils_kozh","array","builtins","dis","encoding_cp932","encoding_cp932_v2","hashlib","html_parser","marshal","math","modulefinder","posix","pyexpat","python_re","python_re_new","unicodedata","xml_helpers","xml_parser","xml_parser_backup"]
__BRYTHON__.compiled_date="2024-07-05 16:40:06.453546"
__BRYTHON__.timestamp=1720212006453
__BRYTHON__.builtin_module_names=["_ajax","_ast","_base64","_binascii","_io_classes","_json","_jsre","_locale","_multiprocessing","_posixsubprocess","_profile","_random","_sre","_sre_utils","_string","_strptime","_svg","_symtable","_tokenize","_webcomponent","_webworker","_zlib_utils","array","builtins","dis","encoding_cp932","hashlib","html_parser","marshal","math","modulefinder","posix","pyexpat","python_re","unicodedata","xml_helpers","xml_parser"]
;

(function($B){const tokens=['ENDMARKER','NAME','NUMBER','STRING','NEWLINE','INDENT','DEDENT','LPAR','RPAR','LSQB','RSQB','COLON','COMMA','SEMI','PLUS','MINUS','STAR','SLASH','VBAR','AMPER','LESS','GREATER','EQUAL','DOT','PERCENT','LBRACE','RBRACE','EQEQUAL','NOTEQUAL','LESSEQUAL','GREATEREQUAL','TILDE','CIRCUMFLEX','LEFTSHIFT','RIGHTSHIFT','DOUBLESTAR','PLUSEQUAL','MINEQUAL','STAREQUAL','SLASHEQUAL','PERCENTEQUAL','AMPEREQUAL','VBAREQUAL','CIRCUMFLEXEQUAL','LEFTSHIFTEQUAL','RIGHTSHIFTEQUAL','DOUBLESTAREQUAL','DOUBLESLASH','DOUBLESLASHEQUAL','AT','ATEQUAL','RARROW','ELLIPSIS','COLONEQUAL','EXCLAMATION','OP','AWAIT','ASYNC','TYPE_IGNORE','TYPE_COMMENT','SOFT_KEYWORD','FSTRING_START','FSTRING_MIDDLE','FSTRING_END','COMMENT','NL',
Expand Down Expand Up @@ -7561,7 +7561,8 @@ if(value===missing ||value===undefined){if(base !==missing){throw _b_.TypeError.
return 0}
if($B.$isinstance(value,[_b_.bytes,_b_.bytearray])){
value=$B.$getattr(value,'decode')('latin-1')}else if(explicit_base && ! $B.$isinstance(value,_b_.str)){throw _b_.TypeError.$factory(
"int() can't convert non-string with explicit base")}else if($B.$isinstance(value,_b_.memoryview)){value=$B.$getattr(_b_.memoryview.tobytes(value),'decode')('latin-1')}
"int() can't convert non-string with explicit base")}else{let klass=$B.get_class(value)
if(klass.$buffer_protocol){value=$B.$getattr(klass.tobytes(value),'decode')('latin-1')}}
if(! $B.$isinstance(value,_b_.str)){if(base !==missing){throw _b_.TypeError.$factory(
"int() can't convert non-string with explicit base")}else{
for(let special_method of['__int__','__index__','__trunc__']){let num_value=$B.$getattr($B.get_class(value),special_method,_b_.None)
Expand All @@ -7584,8 +7585,6 @@ return int_value(res)}}}
throw _b_.TypeError.$factory(
"int() argument must be a string, a bytes-like object "+
`or a real number, not '${$B.class_name(value)}'`)}}
if(value.length==0){throw _b_.ValueError.$factory(
`invalid literal for int() with base 10: ${_b_.repr(value)}`)}
base=base===missing ? 10:$B.PyNumber_Index(base)
if(!(base >=2 && base <=36)){
if(base !=0){throw _b_.ValueError.$factory("invalid base")}}
Expand All @@ -7597,6 +7596,7 @@ var _value=value.trim(),
sign=''
if(_value.startsWith('+')||_value.startsWith('-')){sign=_value[0]
_value=_value.substr(1)}
if(_value.length==0){invalid(base)}
if(_value.length==2 && base==0 &&
(_value=="0b" ||_value=="0o" ||_value=="0x")){throw _b_.ValueError.$factory("invalid value")}
if(_value.endsWith('_')){invalid(base)}
Expand Down Expand Up @@ -7624,7 +7624,9 @@ if(digit < base){res=$B.rich_op('__mul__',res,base)
res=$B.rich_op('__add__',res,digit)}else{invalid(base)}}
return res}else{_value=_value.replace(/_/g,"")}
if(base==2){res=BigInt('0b'+_value)}else if(base==8){res=BigInt('0o'+_value)}else if(base==16){res=BigInt('0x'+_value)}else{if($B.int_max_str_digits !=0 &&
_value.length > $B.int_max_str_digits){throw _b_.ValueError.$factory("Exceeds the limit "+
_value.length > $B.int_max_str_digits &&
((base &(base-1))!==0)
){throw _b_.ValueError.$factory("Exceeds the limit "+
`(${$B.int_max_str_digits}) for integer string conversion: `+
`value has ${value.length} digits; use `+
"sys.set_int_max_str_digits() to increase the limit.")}
Expand Down
6 changes: 3 additions & 3 deletions www/src/brython_stdlib.js

Large diffs are not rendered by default.

20 changes: 12 additions & 8 deletions www/src/py_int.js
Original file line number Diff line number Diff line change
Expand Up @@ -706,8 +706,11 @@ int.$factory = function(){
}else if(explicit_base && ! $B.$isinstance(value, _b_.str)){
throw _b_.TypeError.$factory(
"int() can't convert non-string with explicit base")
}else if($B.$isinstance(value, _b_.memoryview)){
value = $B.$getattr(_b_.memoryview.tobytes(value), 'decode')('latin-1')
}else{
let klass = $B.get_class(value)
if (klass.$buffer_protocol) {
value = $B.$getattr(klass.tobytes(value), 'decode')('latin-1')
}
}

if(! $B.$isinstance(value, _b_.str)){
Expand Down Expand Up @@ -758,10 +761,6 @@ int.$factory = function(){
}
}

if(value.length == 0){
throw _b_.ValueError.$factory(
`invalid literal for int() with base 10: ${_b_.repr(value)}`)
}
base = base === missing ? 10: $B.PyNumber_Index(base)

if(! (base >=2 && base <= 36)){
Expand All @@ -788,6 +787,10 @@ int.$factory = function(){
_value = _value.substr(1)
}

if (_value.length == 0) {
invalid(base)
}

if(_value.length == 2 && base == 0 &&
(_value == "0b" || _value == "0o" || _value == "0x")){
throw _b_.ValueError.$factory("invalid value")
Expand Down Expand Up @@ -880,8 +883,9 @@ int.$factory = function(){
res = BigInt('0x' + _value)
}else{
if($B.int_max_str_digits != 0 &&
_value.length > $B.int_max_str_digits){
throw _b_.ValueError.$factory("Exceeds the limit " +
_value.length > $B.int_max_str_digits &&
((base & (base - 1)) !== 0) // base is not a power of 2
){ throw _b_.ValueError.$factory("Exceeds the limit " +
`(${$B.int_max_str_digits}) for integer string conversion: ` +
`value has ${value.length} digits; use ` +
"sys.set_int_max_str_digits() to increase the limit.")
Expand Down
24 changes: 12 additions & 12 deletions www/src/stdlib_paths.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

87 changes: 41 additions & 46 deletions www/src/version_info.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,41 @@
__BRYTHON__.implementation = [3, 12, 5, 'dev', 0]
__BRYTHON__.version_info = [3, 12, 0, 'final', 0]
__BRYTHON__.compiled_date = "2024-07-04 09:39:49.791767"
__BRYTHON__.timestamp = 1720078789791
__BRYTHON__.builtin_module_names = ["_ajax",
"_ast",
"_base64",
"_binascii",
"_io_classes",
"_json",
"_jsre",
"_locale",
"_multiprocessing",
"_posixsubprocess",
"_profile",
"_random",
"_sre",
"_sre_utils",
"_string",
"_strptime",
"_svg",
"_symtable",
"_tokenize",
"_webcomponent",
"_webworker",
"_zlib_utils",
"_zlib_utils1",
"_zlib_utils_kozh",
"array",
"builtins",
"dis",
"encoding_cp932",
"encoding_cp932_v2",
"hashlib",
"html_parser",
"marshal",
"math",
"modulefinder",
"posix",
"pyexpat",
"python_re",
"python_re_new",
"unicodedata",
"xml_helpers",
"xml_parser",
"xml_parser_backup"]
__BRYTHON__.implementation = [3, 12, 5, 'dev', 0]
__BRYTHON__.version_info = [3, 12, 0, 'final', 0]
__BRYTHON__.compiled_date = "2024-07-05 16:40:06.453546"
__BRYTHON__.timestamp = 1720212006453
__BRYTHON__.builtin_module_names = ["_ajax",
"_ast",
"_base64",
"_binascii",
"_io_classes",
"_json",
"_jsre",
"_locale",
"_multiprocessing",
"_posixsubprocess",
"_profile",
"_random",
"_sre",
"_sre_utils",
"_string",
"_strptime",
"_svg",
"_symtable",
"_tokenize",
"_webcomponent",
"_webworker",
"_zlib_utils",
"array",
"builtins",
"dis",
"encoding_cp932",
"hashlib",
"html_parser",
"marshal",
"math",
"modulefinder",
"posix",
"pyexpat",
"python_re",
"unicodedata",
"xml_helpers",
"xml_parser"]
7 changes: 6 additions & 1 deletion www/tests/run_tests.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<script src="//code.jquery.com/qunit/qunit-2.6.2.js" crossorigin="anonymous"></script>
<script>
QUnit.config.autostart = false;
</script>

<!-- Testem integration -->
<script src="/testem.js"></script>
Expand Down Expand Up @@ -165,9 +168,11 @@

qunit_add_tests(test_utils.load_brython_test_cases('.'))

for test_name in ('test.test_syntax', 'test.test_bool'):
for test_name in ('test.test_syntax', 'test.test_int', 'test.test_bool'):
suite = defaultTestLoader.loadTestsFromName(test_name)
qunit_add_tests(suite, default_caption = 'CPython')

_QUnit.start()
</script>

<!-- for Web Components tests -->
Expand Down