Esempio n. 1
0
def test_add_script():
    ri = ei.RemoteImporter('memory://cache002')
    script = '''
def hello_world():
    print("Hello World)
'''
    ri.add_script('bar.py', script)
    assert ri.db['bar.py']['code'] == script
Esempio n. 2
0
def test_add_script_from_file(script_file):
    script = '''
def ff():
    print("I'm from a file")
'''
    with open(script_file, 'w') as f:
        f.write(script)

    ri = ei.RemoteImporter('memory://cache003')
    key = 'from_file.py'
    ri.add_script_from_file(key, script_file)
    assert ri.db[key]['code'] == script
Esempio n. 3
0
def test_install():
    ri = ei.RemoteImporter('memory://cache001')
    ri.db['foo.py'] = {
        'code': '''
def unittest_add(x, y):
    return x + y
    '''
    }

    ri.install()

    from foo import unittest_add
    assert unittest_add(2, 3) == 5

    import foo
    assert foo.unittest_add(6, 7) == 13
Esempio n. 4
0
def test_uploader(script_file):
    key = 'test_uploader/hello.py'
    script = '''
def ff():
    print("I'm from a file")
'''

    with open(script_file, 'w') as f:
        f.write(script)

    command = [
        "python", "-m", "epimport.uploader", "--srcdb=" + SRCDB,
        "--key=" + key, script_file
    ]

    with Popen(command, stdout=PIPE) as proc:
        output = proc.stdout.read()

    assert proc.returncode == 0
    assert output.decode(
        'ascii') == f"Uploading {script_file} to {SRCDB}/{key}\n"

    ri = ei.RemoteImporter(SRCDB)
    assert (ri.db[key]['code'] == script)
Esempio n. 5
0
def remote_importer():
    ri = epi.RemoteImporter(SRCDB)
    return ri