-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #417 from eendebakpt/symengine_importtime
Improve symengine import time
- Loading branch information
Showing
22 changed files
with
116 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import sys | ||
|
||
try: | ||
import py | ||
from py.test import skip, raises | ||
USE_PYTEST = getattr(sys, '_running_pytest', False) | ||
except ImportError: | ||
USE_PYTEST = False | ||
|
||
if not USE_PYTEST: | ||
def raises(expectedException, code=None): | ||
""" | ||
Tests that ``code`` raises the exception ``expectedException``. | ||
``code`` may be a callable, such as a lambda expression or function | ||
name. | ||
If ``code`` is not given or None, ``raises`` will return a context | ||
manager for use in ``with`` statements; the code to execute then | ||
comes from the scope of the ``with``. | ||
``raises()`` does nothing if the callable raises the expected | ||
exception, otherwise it raises an AssertionError. | ||
Examples | ||
======== | ||
>>> from symengine.pytest import raises | ||
>>> raises(ZeroDivisionError, lambda: 1/0) | ||
>>> raises(ZeroDivisionError, lambda: 1/2) | ||
Traceback (most recent call last): | ||
... | ||
AssertionError: DID NOT RAISE | ||
>>> with raises(ZeroDivisionError): | ||
... n = 1/0 | ||
>>> with raises(ZeroDivisionError): | ||
... n = 1/2 | ||
Traceback (most recent call last): | ||
... | ||
AssertionError: DID NOT RAISE | ||
Note that you cannot test multiple statements via | ||
``with raises``: | ||
>>> with raises(ZeroDivisionError): | ||
... n = 1/0 # will execute and raise, aborting the ``with`` | ||
... n = 9999/0 # never executed | ||
This is just what ``with`` is supposed to do: abort the | ||
contained statement sequence at the first exception and let | ||
the context manager deal with the exception. | ||
To test multiple statements, you'll need a separate ``with`` | ||
for each: | ||
>>> with raises(ZeroDivisionError): | ||
... n = 1/0 # will execute and raise | ||
>>> with raises(ZeroDivisionError): | ||
... n = 9999/0 # will also execute and raise | ||
""" | ||
if code is None: | ||
return RaisesContext(expectedException) | ||
elif callable(code): | ||
try: | ||
code() | ||
except expectedException: | ||
return | ||
raise AssertionError("DID NOT RAISE") | ||
elif isinstance(code, str): | ||
raise TypeError( | ||
'\'raises(xxx, "code")\' has been phased out; ' | ||
'change \'raises(xxx, "expression")\' ' | ||
'to \'raises(xxx, lambda: expression)\', ' | ||
'\'raises(xxx, "statement")\' ' | ||
'to \'with raises(xxx): statement\'') | ||
else: | ||
raise TypeError( | ||
'raises() expects a callable for the 2nd argument.') | ||
|
||
class RaisesContext(object): | ||
def __init__(self, expectedException): | ||
self.expectedException = expectedException | ||
|
||
def __enter__(self): | ||
return None | ||
|
||
def __exit__(self, exc_type, exc_value, traceback): | ||
if exc_type is None: | ||
raise AssertionError("DID NOT RAISE") | ||
return issubclass(exc_type, self.expectedException) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters