def test_path_from_sys_path_assignment():
    SRC = dedent(
        u(
            """
        #!/usr/bin/python

        import sys
        sys.path[0:0] = [
          '/usr/lib/python3.4/site-packages',
          '/home/test/.buildout/eggs/important_package.egg'
          ]

        path[0:0] = [1]

        import important_package

        if __name__ == '__main__':
            sys.exit(important_package.main())"""
        )
    )
    grammar = load_grammar()
    p = ParserWithRecovery(grammar, SRC)
    paths = _check_module(Evaluator(grammar), p.module)
    assert 1 not in paths
    assert "/home/test/.buildout/eggs/important_package.egg" in paths
Example #2
0
def test_path_from_invalid_sys_path_assignment():
    SRC = u("""
import sys
sys.path = 'invalid'""")
    p = Parser(SRC)
    paths = _check_module(p.module)
    assert len(paths) > 0
    assert 'invalid' not in paths
Example #3
0
def test_path_from_invalid_sys_path_assignment():
    SRC = u("""
import sys
sys.path = 'invalid'""")
    p = Parser(SRC)
    paths = _check_module(p.module)
    assert len(paths) > 0
    assert 'invalid' not in paths
Example #4
0
def test_path_from_invalid_sys_path_assignment():
    SRC = dedent(u("""
        import sys
        sys.path = 'invalid'"""))
    grammar = load_grammar()
    p = ParserWithRecovery(grammar, SRC)
    paths = _check_module(Evaluator(grammar), p.module)
    assert len(paths) > 0
    assert 'invalid' not in paths
Example #5
0
def test_path_from_invalid_sys_path_assignment():
    SRC = dedent(u("""
        import sys
        sys.path = 'invalid'"""))
    grammar = load_grammar()
    p = Parser(grammar, SRC)
    paths = _check_module(Evaluator(grammar), p.module)
    assert len(paths) > 0
    assert 'invalid' not in paths
Example #6
0
def test_append_on_non_sys_path():
    SRC = u("""
class Dummy(object):
    path = []

d = Dummy()
d.path.append('foo')""")
    p = Parser(SRC)
    paths = _check_module(p.module)
    assert len(paths) > 0
    assert 'foo' not in paths
Example #7
0
def test_append_on_non_sys_path():
    SRC = u("""
class Dummy(object):
    path = []

d = Dummy()
d.path.append('foo')""")
    p = Parser(SRC)
    paths = _check_module(p.module)
    assert len(paths) > 0
    assert 'foo' not in paths
Example #8
0
def test_append_on_non_sys_path():
    SRC = dedent(u("""
        class Dummy(object):
            path = []

        d = Dummy()
        d.path.append('foo')"""))
    grammar = load_grammar()
    p = Parser(grammar, SRC)
    paths = _check_module(Evaluator(grammar), p.module)
    assert len(paths) > 0
    assert 'foo' not in paths
Example #9
0
def test_append_on_non_sys_path():
    SRC = dedent(
        u("""
        class Dummy(object):
            path = []

        d = Dummy()
        d.path.append('foo')"""))
    grammar = load_grammar()
    p = ParserWithRecovery(grammar, SRC)
    paths = _check_module(Evaluator(grammar), p.module)
    assert len(paths) > 0
    assert 'foo' not in paths
Example #10
0
def test_path_from_sys_path_assignment():
    SRC = u("""
#!/usr/bin/python

import sys
sys.path[0:0] = [
  '/usr/lib/python3.4/site-packages',
  '/home/test/.buildout/eggs/important_package.egg'
  ]

path[0:0] = [1]

import important_package

if __name__ == '__main__':
    sys.exit(important_package.main())""")
    p = Parser(SRC)
    paths = _check_module(p.module)
    assert 1 not in paths
    assert '/home/test/.buildout/eggs/important_package.egg' in paths
Example #11
0
def test_path_from_sys_path_assignment():
    SRC = u("""
#!/usr/bin/python

import sys
sys.path[0:0] = [
  '/usr/lib/python3.4/site-packages',
  '/home/test/.buildout/eggs/important_package.egg'
  ]

path[0:0] = [1]

import important_package

if __name__ == '__main__':
    sys.exit(important_package.main())""")
    p = Parser(SRC)
    paths = _check_module(p.module)
    assert 1 not in paths
    assert '/home/test/.buildout/eggs/important_package.egg' in paths
Example #12
0
def test_path_from_sys_path_assignment():
    SRC = dedent(
        u("""
        #!/usr/bin/python

        import sys
        sys.path[0:0] = [
          '/usr/lib/python3.4/site-packages',
          '/home/test/.buildout/eggs/important_package.egg'
          ]

        path[0:0] = [1]

        import important_package

        if __name__ == '__main__':
            sys.exit(important_package.main())"""))
    grammar = load_grammar()
    p = ParserWithRecovery(grammar, SRC)
    paths = _check_module(Evaluator(grammar), p.module)
    assert 1 not in paths
    assert '/home/test/.buildout/eggs/important_package.egg' in paths
Example #13
0
def check_module_test(code):
    grammar = load_grammar()
    module_context = ModuleContext(Evaluator(grammar), parse(code), path=None)
    return _check_module(module_context)
def check_module_test(code):
    grammar = load_grammar()
    module_context = ModuleContext(Evaluator(grammar), parse(code), path=None)
    return _check_module(module_context)
Example #15
0
def check_module_test(code):
    grammar = load_grammar()
    p = ParserWithRecovery(grammar, code)
    module_context = ModuleContext(Evaluator(grammar), p.module)
    return _check_module(module_context)