예제 #1
0
def test_pex_script(project_name, zip_safe):
    with built_wheel(name=project_name, zip_safe=zip_safe) as bdist_path:
        env_copy = os.environ.copy()
        env_copy["PEX_SCRIPT"] = "hello_world"
        so, rc = run_simple_pex_test("", env=env_copy)
        assert rc == 1, so.decode("utf-8")
        assert b"Could not find script 'hello_world'" in so

        so, rc = run_simple_pex_test("", env=env_copy, dists=[bdist_path])
        assert rc == 0, so.decode("utf-8")
        assert b"hello world" in so

        env_copy["PEX_SCRIPT"] = "shell_script"
        so, rc = run_simple_pex_test("", env=env_copy, dists=[bdist_path])
        assert rc == 1, so.decode("utf-8")
        assert b"Unable to parse" in so
예제 #2
0
def test_entry_point_exit_code():
    setup_py = dedent("""
    from setuptools import setup

    setup(
      name='my_app',
      version='0.0.0',
      zip_safe=True,
      packages=[''],
      entry_points={'console_scripts': ['my_app = my_app:do_something']},
    )
  """)

    error_msg = 'setuptools expects this to exit non-zero'

    my_app = dedent("""
    def do_something():
      return '%s'
  """ % error_msg)

    with temporary_content({
            'setup.py': setup_py,
            'my_app.py': my_app
    }) as project_dir:
        installer = EggInstaller(project_dir)
        dist = DistributionHelper.distribution_from_path(installer.bdist())
        so, rc = run_simple_pex_test('',
                                     env=make_env(PEX_SCRIPT='my_app'),
                                     dists=[dist])
        assert so.decode('utf-8').strip() == error_msg
        assert rc == 1
예제 #3
0
def test_pex_script(project_name, zip_safe):
    with built_wheel(name=project_name, zip_safe=zip_safe) as bdist_path:
        env_copy = os.environ.copy()
        env_copy['PEX_SCRIPT'] = 'hello_world'
        so, rc = run_simple_pex_test('', env=env_copy)
        assert rc == 1, so.decode('utf-8')
        assert b"Could not find script 'hello_world'" in so

        so, rc = run_simple_pex_test('', env=env_copy, dists=[bdist_path])
        assert rc == 0, so.decode('utf-8')
        assert b'hello world' in so

        env_copy['PEX_SCRIPT'] = 'shell_script'
        so, rc = run_simple_pex_test('', env=env_copy, dists=[bdist_path])
        assert rc == 1, so.decode('utf-8')
        assert b'Unable to parse' in so
예제 #4
0
def test_entry_point_exit_code():
  setup_py = dedent("""
    from setuptools import setup

    setup(
      name='my_app',
      version='0.0.0',
      zip_safe=True,
      packages=[''],
      entry_points={'console_scripts': ['my_app = my_app:do_something']},
    )
  """)

  error_msg = 'setuptools expects this to exit non-zero'

  my_app = dedent("""
    def do_something():
      return '%s'
  """ % error_msg)

  with temporary_content({'setup.py': setup_py, 'my_app.py': my_app}) as project_dir:
    installer = EggInstaller(project_dir)
    dist = DistributionHelper.distribution_from_path(installer.bdist())
    so, rc = run_simple_pex_test('', env={'PEX_SCRIPT': 'my_app'}, dists=[dist])
    assert so.decode('utf-8').strip() == error_msg
    assert rc == 1
예제 #5
0
파일: test_pex.py 프로젝트: davinirjr/pex
def test_pex_script(installer_impl, project_name):
  with make_installer(name=project_name, installer_impl=installer_impl) as installer:
    bdist = DistributionHelper.distribution_from_path(installer.bdist())

    env_copy = os.environ.copy()
    env_copy['PEX_SCRIPT'] = 'hello_world'
    so, rc = run_simple_pex_test('', env=env_copy)
    assert rc == 1, so.decode('utf-8')
    assert b'Could not find' in so

    so, rc = run_simple_pex_test('', env=env_copy, dists=[bdist])
    assert rc == 0, so.decode('utf-8')
    assert b'hello world' in so

    env_copy['PEX_SCRIPT'] = 'shell_script'
    so, rc = run_simple_pex_test('', env=env_copy, dists=[bdist])
    assert rc == 1, so.decode('utf-8')
    assert b'Unable to parse' in so
예제 #6
0
def test_pex_script(installer_impl, project_name, zip_safe):
  kw = dict(name=project_name, installer_impl=installer_impl, zip_safe=zip_safe)
  with make_installer(**kw) as installer:
    bdist = DistributionHelper.distribution_from_path(installer.bdist())

    env_copy = os.environ.copy()
    env_copy['PEX_SCRIPT'] = 'hello_world'
    so, rc = run_simple_pex_test('', env=env_copy)
    assert rc == 1, so.decode('utf-8')
    assert b'Could not find script hello_world' in so

    so, rc = run_simple_pex_test('', env=env_copy, dists=[bdist])
    assert rc == 0, so.decode('utf-8')
    assert b'hello world' in so

    env_copy['PEX_SCRIPT'] = 'shell_script'
    so, rc = run_simple_pex_test('', env=env_copy, dists=[bdist])
    assert rc == 1, so.decode('utf-8')
    assert b'Unable to parse' in so
예제 #7
0
파일: test_pex.py 프로젝트: yolken/pex
def test_pex_atexit_swallowing():
    body = textwrap.dedent("""
  import atexit

  def raise_on_exit():
    raise Exception('This is an exception')

  atexit.register(raise_on_exit)
  """)

    so, rc = run_simple_pex_test(body)
    assert so == b''
    assert rc == 0

    env_copy = os.environ.copy()
    env_copy.update(PEX_TEARDOWN_VERBOSE='1')
    so, rc = run_simple_pex_test(body, env=env_copy)
    assert b'This is an exception' in so
    assert rc == 0
예제 #8
0
파일: test_pex.py 프로젝트: clam-gpsw/pex
def test_pex_atexit_swallowing():
  body = textwrap.dedent("""
  import atexit

  def raise_on_exit():
    raise Exception('This is an exception')

  atexit.register(raise_on_exit)
  """)

  so, rc = run_simple_pex_test(body)
  assert so == b''
  assert rc == 0

  env_copy = os.environ.copy()
  env_copy.update(PEX_TEARDOWN_VERBOSE='1')
  so, rc = run_simple_pex_test(body, env=env_copy)
  assert b'This is an exception' in so
  assert rc == 0
예제 #9
0
def test_pex_interpreter():
  with named_temporary_file() as fp:
    fp.write(b"print('Hello world')")
    fp.flush()

    env = make_env(PEX_INTERPRETER=1)

    so, rc = run_simple_pex_test("", args=(fp.name,), coverage=True, env=env)
    assert so == b'Hello world\n'
    assert rc == 0
예제 #10
0
def test_pex_python_symlink():
    with temporary_dir() as td:
        symlink_path = os.path.join(td, 'python-symlink')
        os.symlink(sys.executable, symlink_path)
        pexrc_path = os.path.join(td, '.pexrc')
        with open(pexrc_path, 'w') as pexrc:
            pexrc.write("PEX_PYTHON=%s" % symlink_path)

        body = "print('Hello')"
        _, rc = run_simple_pex_test(body, coverage=True, env=make_env(HOME=td))
        assert rc == 0
예제 #11
0
def test_pex_interpreter():
  with named_temporary_file() as fp:
    fp.write(b"print('Hello world')")
    fp.flush()

    env = os.environ.copy()
    env['PEX_INTERPRETER'] = '1'

    so, rc = run_simple_pex_test("", args=(fp.name,), coverage=True, env=env)
    assert so == b'Hello world\n'
    assert rc == 0
예제 #12
0
def test_pex_python_symlink():
  with temporary_dir() as td:
    with environment_as(HOME=td):
      symlink_path = os.path.join(td, 'python-symlink')
      os.symlink(sys.executable, symlink_path)
      pexrc_path = os.path.join(td, '.pexrc')
      with open(pexrc_path, 'w') as pexrc:
        pexrc.write("PEX_PYTHON=%s" % symlink_path)

      body = "print('Hello')"
      _, rc = run_simple_pex_test(body, coverage=True)
      assert rc == 0
예제 #13
0
def test_pex_interpreter():
    with temporary_file() as fp:
        fp.write(b"print('Hello world')")
        fp.flush()

        env = os.environ.copy()
        env['PEX_INTERPRETER'] = '1'

        so, rc = run_simple_pex_test("",
                                     args=(fp.name, ),
                                     coverage=True,
                                     env=env)
        assert so == b'Hello world\n'
        assert rc == 0
예제 #14
0
파일: test_pex.py 프로젝트: clam-gpsw/pex
def test_excepthook_honored():
  body = textwrap.dedent("""
  import sys

  def excepthook(ex_type, ex, tb):
    print('Custom hook called with: {0}'.format(ex))
    sys.exit(42)

  sys.excepthook = excepthook

  raise Exception('This is an exception')
  """)

  so, rc = run_simple_pex_test(body)
  assert so == b'Custom hook called with: This is an exception\n', 'Standard out was: %s' % so
  assert rc == 42
예제 #15
0
파일: test_pex.py 프로젝트: yolken/pex
def test_excepthook_honored():
    body = textwrap.dedent("""
  import sys

  def excepthook(ex_type, ex, tb):
    print('Custom hook called with: {0}'.format(ex))
    sys.exit(42)

  sys.excepthook = excepthook

  raise Exception('This is an exception')
  """)

    so, rc = run_simple_pex_test(body)
    assert so == b'Custom hook called with: This is an exception\n', 'Standard out was: %s' % so
    assert rc == 42
예제 #16
0
def test_pex_sys_exit_does_not_raise():
    body = "import sys; sys.exit(2)"
    so, rc = run_simple_pex_test(body)
    assert so == b'', 'Should not print SystemExit exception.'
    assert rc == 2
예제 #17
0
파일: test_pex.py 프로젝트: clam-gpsw/pex
def test_pex_uncaught_exceptions():
  body = "raise Exception('This is an exception')"
  so, rc = run_simple_pex_test(body)
  assert b'This is an exception' in so, 'Standard out was: %s' % so
  assert rc == 1
예제 #18
0
파일: test_pex.py 프로젝트: yolken/pex
def test_pex_uncaught_exceptions():
    body = "raise Exception('This is an exception')"
    so, rc = run_simple_pex_test(body)
    assert b'This is an exception' in so, 'Standard out was: %s' % so
    assert rc == 1
예제 #19
0
def test_pex_execute():
    body = "print('Hello')"
    _, rc = run_simple_pex_test(body, coverage=True)
    assert rc == 0
예제 #20
0
def test_pex_raise():
    body = "raise Exception('This will improve coverage.')"
    run_simple_pex_test(body, coverage=True)
예제 #21
0
파일: test_pex.py 프로젝트: Yasumoto/pex
def test_pex_sys_exit_does_not_raise():
  body = "import sys; sys.exit(2)"
  so, rc = run_simple_pex_test(body)
  assert so == b'', 'Should not print SystemExit exception.'
  assert rc == 2
예제 #22
0
파일: test_pex.py 프로젝트: clam-gpsw/pex
def _test_sys_exit(arg, expected_output, expected_rc):
  body = "import sys; sys.exit({arg})".format(arg=arg)
  so, rc = run_simple_pex_test(body)
  assert so == expected_output, 'Should not print SystemExit traceback.'
  assert rc == expected_rc
예제 #23
0
def _test_sys_exit(arg, expected_output, expected_rc):
    # type: (Union[str, int], bytes, int) -> None
    body = "import sys; sys.exit({arg})".format(arg=arg)
    so, rc = run_simple_pex_test(body)
    assert so == expected_output, "Should not print SystemExit traceback."
    assert rc == expected_rc
예제 #24
0
파일: test_pex.py 프로젝트: yolken/pex
def _test_sys_exit(arg, expected_output, expected_rc):
    body = "import sys; sys.exit({arg})".format(arg=arg)
    so, rc = run_simple_pex_test(body)
    assert so == expected_output, 'Should not print SystemExit traceback.'
    assert rc == expected_rc
예제 #25
0
def test_pex_raise():
  body = "raise Exception('This will improve coverage.')"
  run_simple_pex_test(body, coverage=True)
예제 #26
0
def test_pex_execute():
  body = "print('Hello')"
  _, rc = run_simple_pex_test(body, coverage=True)
  assert rc == 0
예제 #27
0
def test_pex_uncaught_exceptions():
    # type: () -> None
    body = "raise Exception('This is an exception')"
    so, rc = run_simple_pex_test(body)
    assert b"This is an exception" in so, "Standard out was: %r" % so
    assert rc == 1