Exemple #1
0
def test_recursive_attribute(py2venv):
    """
    A trivial test proving that we have recursive
    attribute access to a real python2 object.
    """
    p2sys = sux.to_use('sys')
    assert p2sys.version_info.major == 2
Exemple #2
0
def test_override_env(py2venv):
    """
    Env can be supplied
    """
    env = {"FOO": "BAR"}
    test_env = sux.to_use('py2sux.envtest', env=env)
    assert "BAR" == test_env.get_env("FOO").decode('utf-8')
Exemple #3
0
def test_default_env(py2venv):
    """
    Py3 env is not inherited by default
    """
    test_env = sux.to_use('py2sux.envtest')

    with pytest.raises(sux.exceptions.KeyError):
        test_env.get_env('PATH')
Exemple #4
0
def test_urlparse(py2venv):
    """
    A trivial test importing a package
    which does not exist in python3
    """
    up = sux.to_use('urlparse')
    assert {} == up.parse_qs("")
    assert 'http://www.cwi.nl/%7Eguido/FAQ.html' == \
        up.urljoin('http://www.cwi.nl/%7Eguido/Python.html', 'FAQ.html')
Exemple #5
0
def test_dunder_add(py2venv):
    """
    Demonstrate that the __add__ operator is correctly
    relayed to python2 land.
    """
    native_args = sux.to_use('py2sux.native_args')

    n1 = native_args.Python2Native(4)
    n2 = native_args.Python2Native(5)
    assert 9 == n1 + n2
Exemple #6
0
def test_proper_exception_raised(py2venv):
    """
    Using boto, demonstrate that the right exception
    is raised, with both the same name and text
    as the original exception.
    """
    py2venv.install("boto==2.31.1")
    connection = sux.to_use('boto.s3.connection')
    conn = connection.S3Connection('abc', '123')
    exception_info = raises(sux.exceptions.S3ResponseError,
            conn.create_bucket, "foo")
    assert "AWS Access Key Id" in str(exception_info)
def test_multiple_refs(py2venv):
    """
    When the same python2 object is referred to twice, and then
    one reference is garbage collected, ensure the object is
    still available in python2 land.
    """
    py2venv.install("boto==2.31.1")
    connection = sux.to_use('boto.s3.connection')
    # create two references to the same object
    conn1 = connection.S3Connection
    conn2 = connection.S3Connection
    # decrement one refcount to zero and let it be garbage collected
    del conn1
    gc.collect()
    # confirm we can still perform remote operations on this object
    conn2("abc", "123")
Exemple #8
0
def test_sys_on_python2(py2venv):
    p2sys = sux.to_use('sys', cwd=py2sux_dir)
    assert p2sys.version_info.major == 2