Exemple #1
0
def test_write_scope_nested():
    target_path = "./tests/fixtures/write_scope4.txt"
    if os.path.exists(target_path):
        os.remove(target_path)

    with io_scope("./tests"):
        with io_scope("fixtures"):
            write("test", "write_scope4.txt", mode="w")

    assert os.path.isfile(target_path)
Exemple #2
0
def test_batch_load():
    image_names = [os.path.basename(image) for image in test_images]
    with io_scope('./tests/fixtures'):
        images = load(image_names)
    assert len(images) == len(test_images)
    for i in range(len(test_images)):
        assert np.allclose(load(test_images[i]), images[i])
Exemple #3
0
def test_write_scope_compatibility():
    path = "./tests/fixtures/write_scope_compatibility.txt"
    _remove(path)

    with io_scope("./tests/fixtures"):
        save("test", "write_scope_compatibility.txt")

    assert os.path.isfile(path)
Exemple #4
0
def test_write_scope_compatibility():
    path = "./tests/fixtures/generated_outputs/write_scope_compatibility.txt"
    _remove(path)

    with io_scope("./tests/fixtures/generated_outputs"):
        save("test content", 'write_scope_compatibility.txt')

    assert os.path.isfile(path)
Exemple #5
0
def test_capturing_saves():
    path = "./tests/fixtures/generated_outputs/test_capturing_saves.txt"
    _remove(path)
    context = CaptureSaveContext()

    with context, io_scope("./tests/fixtures/generated_outputs"):
        save("test", "test_capturing_saves.txt")

    captured = context.captured_saves
    assert len(captured) == 1
    assert "type" in captured[0]
    assert captured[0]["type"] == "txt"
Exemple #6
0
def test_batch_saves():
    save_ops = [(str(i), f"write_batch_{i}.txt") for i in range(5)]
    [
        _remove(f"./tests/fixtures/generated_outputs/write_batch_{i}.txt")
        for i in range(5)
    ]

    context = CaptureSaveContext()
    with context, io_scope("./tests/fixtures/generated_outputs"):
        results = batch_save(save_ops)
        assert len(results) == 5

    assert len(context.captured_saves) == 5
    assert context.captured_saves[0]['type'] == 'txt'
    print(context.captured_saves)
    assert 'write_batch_' in context.captured_saves[0]['url']
    assert all([
        os.path.isfile(
            f"./tests/fixtures/generated_outputs/write_batch_{i}.txt")
        for i in range(5)
    ])
Exemple #7
0
 def _return_io_scope(io_scope_path):
     with io_scope(io_scope_path):
         time.sleep(np.random.uniform(0.05, 0.1))
         return current_io_scopes()[-1]