Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_classes():
try: #XXX: should this be a 'special case'?
from StringIO import StringIO
x = "from StringIO import StringIO\n"
y = x
except ImportError:
from io import BytesIO as StringIO
x = "from io import BytesIO\n"
y = "from _io import BytesIO\n"
s = StringIO()
assert likely_import(StringIO) == x
assert likely_import(s) == y
# interactively defined classes and class instances
assert likely_import(Foo) == 'from %s import Foo\n' % __name__
assert likely_import(_foo) == 'from %s import Foo\n' % __name__
def test_classes():
try: #XXX: should this be a 'special case'?
from StringIO import StringIO
x = "from StringIO import StringIO\n"
y = x
except ImportError:
from io import BytesIO as StringIO
x = "from io import BytesIO\n"
y = "from _io import BytesIO\n"
s = StringIO()
assert likely_import(StringIO) == x
assert likely_import(s) == y
# interactively defined classes and class instances
assert likely_import(Foo) == 'from %s import Foo\n' % __name__
assert likely_import(_foo) == 'from %s import Foo\n' % __name__
def test_builtin():
if PY3: builtin = 'builtins'
else: builtin = '__builtin__'
assert likely_import(pow) == 'pow\n'
assert likely_import(100) == '100\n'
assert likely_import(True) == 'True\n'
assert likely_import(pow, explicit=True) == 'from %s import pow\n' % builtin
assert likely_import(100, explicit=True) == '100\n'
assert likely_import(True, explicit=True) == 'True\n' if PY3 else 'from %s import True\n' % builtin
# this is kinda BS... you can't import a None
assert likely_import(None) == 'None\n'
assert likely_import(None, explicit=True) == 'None\n'
def test_classes():
try: #XXX: should this be a 'special case'?
from StringIO import StringIO
x = "from StringIO import StringIO\n"
y = x
except ImportError:
from io import BytesIO as StringIO
x = "from io import BytesIO\n"
y = "from _io import BytesIO\n"
s = StringIO()
assert likely_import(StringIO) == x
assert likely_import(s) == y
# interactively defined classes and class instances
assert likely_import(Foo) == 'from %s import Foo\n' % __name__
assert likely_import(_foo) == 'from %s import Foo\n' % __name__
def test_builtin():
if PY3: builtin = 'builtins'
else: builtin = '__builtin__'
assert likely_import(pow) == 'pow\n'
assert likely_import(100) == '100\n'
assert likely_import(True) == 'True\n'
assert likely_import(pow, explicit=True) == 'from %s import pow\n' % builtin
assert likely_import(100, explicit=True) == '100\n'
assert likely_import(True, explicit=True) == 'True\n' if PY3 else 'from %s import True\n' % builtin
# this is kinda BS... you can't import a None
assert likely_import(None) == 'None\n'
assert likely_import(None, explicit=True) == 'None\n'
def test_itself():
assert likely_import(likely_import)=='from dill.source import likely_import\n'
def test_builtin():
if PY3: builtin = 'builtins'
else: builtin = '__builtin__'
assert likely_import(pow) == 'pow\n'
assert likely_import(100) == '100\n'
assert likely_import(True) == 'True\n'
assert likely_import(pow, explicit=True) == 'from %s import pow\n' % builtin
assert likely_import(100, explicit=True) == '100\n'
assert likely_import(True, explicit=True) == 'True\n' if PY3 else 'from %s import True\n' % builtin
# this is kinda BS... you can't import a None
assert likely_import(None) == 'None\n'
assert likely_import(None, explicit=True) == 'None\n'
def test_imported():
from math import sin
assert likely_import(sin) == 'from math import sin\n'