Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
67f8db8
Add gitpod configuration
coolreader18 Feb 3, 2020
4228c76
Add Gitpod badge
coolreader18 Feb 4, 2020
0aac4f6
Add GH actions badge
coolreader18 Feb 4, 2020
adad962
Install rls in .gitpod.Dockerfile
coolreader18 Feb 4, 2020
c84ab03
Add test_baseexception from CPython 3.8
palaviv Feb 10, 2020
2bd932c
Mark unsupported tests
palaviv Feb 10, 2020
5f1c62b
Add test_int_literal from CPython 3.8
palaviv Feb 10, 2020
5c2b25c
Add test_int from CPython 3.8
palaviv Feb 10, 2020
2e06913
Mark unsupported tests
palaviv Feb 10, 2020
63f00f4
Add test_opcodes from CPython 3.8
palaviv Feb 10, 2020
df99dd1
Mark unsupported tests
palaviv Feb 10, 2020
e5ea094
Add test_pow from CPython 3.8
palaviv Feb 10, 2020
def812f
Add test_raise from CPython 3.8
palaviv Feb 10, 2020
eb767cd
Mark unsupported tests
palaviv Feb 10, 2020
74b74d3
Make _random work on wasm
coolreader18 Feb 13, 2020
2355ac7
Remove test warnings
youknowone Feb 18, 2020
749d643
Allow star expression for list elements
youknowone Feb 16, 2020
1a3d5b2
Reorganize struct module, add struct.Struct
coolreader18 Feb 21, 2020
18d16ee
Add struct.Struct test
coolreader18 Feb 21, 2020
8af74da
Add struct.Struct.size property
coolreader18 Feb 21, 2020
aa26ee1
Misc changes
coolreader18 Feb 21, 2020
e9beca4
Support Args in set/frozenset methods
palaviv Feb 16, 2020
9a5a5fb
Add test_set from CPython 3.8
palaviv Feb 16, 2020
3affa0d
Mark unsupported tests
palaviv Feb 16, 2020
4e05727
Throw errors for invalid f-strings, allow != in f-string braces, tests.
philippeitis Feb 26, 2020
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
14 changes: 14 additions & 0 deletions .gitpod.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM gitpod/workspace-full

USER gitpod

# Update Rust to the latest version
RUN rm -rf ~/.rustup && \
export PATH=$HOME/.cargo/bin:$PATH && \
rustup update stable && \
rustup component add rls && \
# Set up wasm-pack and wasm32-unknown-unknown for rustpython_wasm
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh && \
rustup target add wasm32-unknown-unknown

USER root
2 changes: 2 additions & 0 deletions .gitpod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
image:
file: .gitpod.Dockerfile
1 change: 1 addition & 0 deletions Cargo.lock

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

8 changes: 7 additions & 1 deletion Lib/random.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@
from types import MethodType as _MethodType, BuiltinMethodType as _BuiltinMethodType
from math import log as _log, exp as _exp, pi as _pi, e as _e, ceil as _ceil
from math import sqrt as _sqrt, acos as _acos, cos as _cos, sin as _sin
from os import urandom as _urandom
try:
from os import urandom as _urandom
except ImportError:
# On wasm, _random.Random.random() does give a proper random value, but
# we don't have the os module
def _urandom(*args, **kwargs):
raise NotImplementedError("urandom")
from _collections_abc import Set as _Set, Sequence as _Sequence
from hashlib import sha512 as _sha512
import itertools as _itertools
Expand Down
15 changes: 15 additions & 0 deletions Lib/struct.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
__all__ = [
# Functions
'calcsize', 'pack', 'pack_into', 'unpack', 'unpack_from',
'iter_unpack',

# Classes
'Struct',

# Exceptions
'error'
]

from _struct import *
from _struct import _clearcache
from _struct import __doc__
65 changes: 65 additions & 0 deletions Lib/test/exception_hierarchy.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
BaseException
+-- SystemExit
+-- KeyboardInterrupt
+-- GeneratorExit
+-- Exception
+-- StopIteration
+-- StopAsyncIteration
+-- ArithmeticError
| +-- FloatingPointError
| +-- OverflowError
| +-- ZeroDivisionError
+-- AssertionError
+-- AttributeError
+-- BufferError
+-- EOFError
+-- ImportError
| +-- ModuleNotFoundError
+-- LookupError
| +-- IndexError
| +-- KeyError
+-- MemoryError
+-- NameError
| +-- UnboundLocalError
+-- OSError
| +-- BlockingIOError
| +-- ChildProcessError
| +-- ConnectionError
| | +-- BrokenPipeError
| | +-- ConnectionAbortedError
| | +-- ConnectionRefusedError
| | +-- ConnectionResetError
| +-- FileExistsError
| +-- FileNotFoundError
| +-- InterruptedError
| +-- IsADirectoryError
| +-- NotADirectoryError
| +-- PermissionError
| +-- ProcessLookupError
| +-- TimeoutError
+-- ReferenceError
+-- RuntimeError
| +-- NotImplementedError
| +-- RecursionError
+-- SyntaxError
| +-- TargetScopeError
| +-- IndentationError
| +-- TabError
+-- SystemError
+-- TypeError
+-- ValueError
| +-- UnicodeError
| +-- UnicodeDecodeError
| +-- UnicodeEncodeError
| +-- UnicodeTranslateError
+-- Warning
+-- DeprecationWarning
+-- PendingDeprecationWarning
+-- RuntimeWarning
+-- SyntaxWarning
+-- UserWarning
+-- FutureWarning
+-- ImportWarning
+-- UnicodeWarning
+-- BytesWarning
+-- ResourceWarning
189 changes: 189 additions & 0 deletions Lib/test/test_baseexception.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
import unittest
import builtins
import os
from platform import system as platform_system


class ExceptionClassTests(unittest.TestCase):

"""Tests for anything relating to exception objects themselves (e.g.,
inheritance hierarchy)"""

def test_builtins_new_style(self):
self.assertTrue(issubclass(Exception, object))

def verify_instance_interface(self, ins):
for attr in ("args", "__str__", "__repr__"):
self.assertTrue(hasattr(ins, attr),
"%s missing %s attribute" %
(ins.__class__.__name__, attr))

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_inheritance(self):
# Make sure the inheritance hierarchy matches the documentation
exc_set = set()
for object_ in builtins.__dict__.values():
try:
if issubclass(object_, BaseException):
exc_set.add(object_.__name__)
except TypeError:
pass

inheritance_tree = open(os.path.join(os.path.split(__file__)[0],
'exception_hierarchy.txt'))
try:
superclass_name = inheritance_tree.readline().rstrip()
try:
last_exc = getattr(builtins, superclass_name)
except AttributeError:
self.fail("base class %s not a built-in" % superclass_name)
self.assertIn(superclass_name, exc_set,
'%s not found' % superclass_name)
exc_set.discard(superclass_name)
superclasses = [] # Loop will insert base exception
last_depth = 0
for exc_line in inheritance_tree:
exc_line = exc_line.rstrip()
depth = exc_line.rindex('-')
exc_name = exc_line[depth+2:] # Slice past space
if '(' in exc_name:
paren_index = exc_name.index('(')
platform_name = exc_name[paren_index+1:-1]
exc_name = exc_name[:paren_index-1] # Slice off space
if platform_system() != platform_name:
exc_set.discard(exc_name)
continue
if '[' in exc_name:
left_bracket = exc_name.index('[')
exc_name = exc_name[:left_bracket-1] # cover space
try:
exc = getattr(builtins, exc_name)
except AttributeError:
self.fail("%s not a built-in exception" % exc_name)
if last_depth < depth:
superclasses.append((last_depth, last_exc))
elif last_depth > depth:
while superclasses[-1][0] >= depth:
superclasses.pop()
self.assertTrue(issubclass(exc, superclasses[-1][1]),
"%s is not a subclass of %s" % (exc.__name__,
superclasses[-1][1].__name__))
try: # Some exceptions require arguments; just skip them
self.verify_instance_interface(exc())
except TypeError:
pass
self.assertIn(exc_name, exc_set)
exc_set.discard(exc_name)
last_exc = exc
last_depth = depth
finally:
inheritance_tree.close()
self.assertEqual(len(exc_set), 0, "%s not accounted for" % exc_set)

interface_tests = ("length", "args", "str", "repr")

def interface_test_driver(self, results):
for test_name, (given, expected) in zip(self.interface_tests, results):
self.assertEqual(given, expected, "%s: %s != %s" % (test_name,
given, expected))

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_interface_single_arg(self):
# Make sure interface works properly when given a single argument
arg = "spam"
exc = Exception(arg)
results = ([len(exc.args), 1], [exc.args[0], arg],
[str(exc), str(arg)],
[repr(exc), '%s(%r)' % (exc.__class__.__name__, arg)])
self.interface_test_driver(results)

def test_interface_multi_arg(self):
# Make sure interface correct when multiple arguments given
arg_count = 3
args = tuple(range(arg_count))
exc = Exception(*args)
results = ([len(exc.args), arg_count], [exc.args, args],
[str(exc), str(args)],
[repr(exc), exc.__class__.__name__ + repr(exc.args)])
self.interface_test_driver(results)

def test_interface_no_arg(self):
# Make sure that with no args that interface is correct
exc = Exception()
results = ([len(exc.args), 0], [exc.args, tuple()],
[str(exc), ''],
[repr(exc), exc.__class__.__name__ + '()'])
self.interface_test_driver(results)

class UsageTests(unittest.TestCase):

"""Test usage of exceptions"""

def raise_fails(self, object_):
"""Make sure that raising 'object_' triggers a TypeError."""
try:
raise object_
except TypeError:
return # What is expected.
self.fail("TypeError expected for raising %s" % type(object_))

def catch_fails(self, object_):
"""Catching 'object_' should raise a TypeError."""
try:
try:
raise Exception
except object_:
pass
except TypeError:
pass
except Exception:
self.fail("TypeError expected when catching %s" % type(object_))

try:
try:
raise Exception
except (object_,):
pass
except TypeError:
return
except Exception:
self.fail("TypeError expected when catching %s as specified in a "
"tuple" % type(object_))

def test_raise_new_style_non_exception(self):
# You cannot raise a new-style class that does not inherit from
# BaseException; the ability was not possible until BaseException's
# introduction so no need to support new-style objects that do not
# inherit from it.
class NewStyleClass(object):
pass
self.raise_fails(NewStyleClass)
self.raise_fails(NewStyleClass())

def test_raise_string(self):
# Raising a string raises TypeError.
self.raise_fails("spam")

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_catch_non_BaseException(self):
# Trying to catch an object that does not inherit from BaseException
# is not allowed.
class NonBaseException(object):
pass
self.catch_fails(NonBaseException)
self.catch_fails(NonBaseException())

def test_catch_BaseException_instance(self):
# Catching an instance of a BaseException subclass won't work.
self.catch_fails(BaseException())

def test_catch_string(self):
# Catching a string is bad.
self.catch_fails("spam")


if __name__ == '__main__':
unittest.main()
Loading