mirror of
https://github.com/pocketpy/pocketpy
synced 2026-02-10 01:20:18 +00:00
add tests for .pyc
This commit is contained in:
parent
d3d83bd126
commit
3e182d5c6b
@ -3,14 +3,12 @@ import sys
|
|||||||
import time
|
import time
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
pkpy_exe = 'main.exe' if sys.platform == 'win32' else './main'
|
||||||
|
|
||||||
def test_file(filepath, cpython=False):
|
def test_file(filepath, cpython=False):
|
||||||
if cpython:
|
if cpython:
|
||||||
return os.system("python " + filepath) == 0
|
return os.system("python " + filepath) == 0
|
||||||
if sys.platform == 'win32':
|
code = os.system(pkpy_exe + ' ' + filepath)
|
||||||
code = os.system("main.exe " + filepath)
|
|
||||||
else:
|
|
||||||
code = os.system("./main " + filepath)
|
|
||||||
if code != 0:
|
if code != 0:
|
||||||
print('Return code:', code)
|
print('Return code:', code)
|
||||||
return code == 0
|
return code == 0
|
||||||
@ -18,7 +16,7 @@ def test_file(filepath, cpython=False):
|
|||||||
def test_dir(path):
|
def test_dir(path):
|
||||||
print("Testing directory:", path)
|
print("Testing directory:", path)
|
||||||
for filename in sorted(os.listdir(path)):
|
for filename in sorted(os.listdir(path)):
|
||||||
if not filename.endswith('.py'):
|
if not filename.endswith('.py') and not filename.endswith('.pyc'):
|
||||||
continue
|
continue
|
||||||
filepath = os.path.join(path, filename)
|
filepath = os.path.join(path, filename)
|
||||||
print("> " + filepath, flush=True)
|
print("> " + filepath, flush=True)
|
||||||
@ -76,6 +74,8 @@ exit()
|
|||||||
print(res.stdout)
|
print(res.stdout)
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
|
code = os.system(f'python compileall.py {pkpy_exe} tests tmp/tests')
|
||||||
|
assert code == 0
|
||||||
|
|
||||||
if len(sys.argv) == 2:
|
if len(sys.argv) == 2:
|
||||||
assert 'benchmark' in sys.argv[1]
|
assert 'benchmark' in sys.argv[1]
|
||||||
@ -84,5 +84,11 @@ else:
|
|||||||
test_dir('tests/')
|
test_dir('tests/')
|
||||||
test_repl()
|
test_repl()
|
||||||
|
|
||||||
|
if os.path.exists('tmp/tests'):
|
||||||
|
print('-' * 50)
|
||||||
|
time.sleep(3)
|
||||||
|
test_dir('tmp/tests/')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
print("ALL TESTS PASSED")
|
print("ALL TESTS PASSED")
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
filename = 'tests/801_sys.py'
|
assert (sys.argv in [
|
||||||
assert (sys.argv == [filename]), sys.argv
|
['tests/801_sys.py'],
|
||||||
|
['tmp/tests/801_sys.pyc'],
|
||||||
|
]), sys.argv
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,8 @@
|
|||||||
import traceback
|
import traceback
|
||||||
|
import sys
|
||||||
|
|
||||||
|
if sys.argv[0].endswith('.pyc'):
|
||||||
|
exit()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
a = {'123': 4}
|
a = {'123': 4}
|
||||||
@ -7,7 +11,7 @@ except KeyError:
|
|||||||
actual = traceback.format_exc()
|
actual = traceback.format_exc()
|
||||||
|
|
||||||
expected = '''Traceback (most recent call last):
|
expected = '''Traceback (most recent call last):
|
||||||
File "tests/802_traceback.py", line 5
|
File "tests/802_traceback.py", line 9
|
||||||
b = a[6]
|
b = a[6]
|
||||||
KeyError: 6'''
|
KeyError: 6'''
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user