How to use the dill.source.likely_import function in dill

To help you get started, we’ve selected a few dill examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github uqfoundation / dill / tests / test_source.py View on Github external
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__
github uqfoundation / dill / tests / test_source.py View on Github external
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__
github uqfoundation / dill / tests / test_source.py View on Github external
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'
github uqfoundation / dill / tests / test_source.py View on Github external
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__
github uqfoundation / dill / tests / test_source.py View on Github external
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'
github uqfoundation / dill / tests / test_source.py View on Github external
def test_itself():
  assert likely_import(likely_import)=='from dill.source import likely_import\n'
github uqfoundation / dill / tests / test_source.py View on Github external
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'
github uqfoundation / dill / tests / test_source.py View on Github external
def test_imported():
  from math import sin
  assert likely_import(sin) == 'from math import sin\n'