Example #1
0
def test_loader_broken_image():
    manifest = random_manifest(2, broken_image_index=1)
    config = generic_config(manifest.name, batch_size)

    with pytest.raises(Exception) as ex:
        dl = DataLoader(config)
    assert 'Decoding image failed due to invalid data in the image file' in str(ex)
def test_loader_repeat_iter():
    # NOTE: manifest needs to stay in scope until DataLoader has read it.
    manifest = random_manifest(10)
    config = generic_config(manifest.name, batch_size)

    dl = DataLoader(config)

    assert len(list(iter(dl))) == math.ceil(10. / batch_size)
Example #3
0
def test_loader_exception_iter():
    # NOTE: manifest needs to stay in scope until DataLoader has read it.
    manifest = random_manifest(10, 2)
    config = generic_config(manifest.name)

    dl = DataLoader(config, gen_backend('cpu'))

    assert len(list(iter(dl))) == 4
Example #4
0
def test_loader_invalid_config_type():
    manifest = random_manifest(10)
    config = generic_config(manifest.name)

    config['type'] = 'invalid type name'

    with pytest.raises(Exception) as ex:
        dl = DataLoader(config, gen_backend('cpu'))
def test_loader():
    # NOTE: manifest needs to stay in scope until DataLoader has read it.
    for i in range(1, 10):
        manifest = random_manifest(i)
        config = generic_config(manifest.name, batch_size)

        dl = DataLoader(config)

        assert len(list(iter(dl))) == math.ceil(float(i) / batch_size)
def test_loader_missing_config_field():
    manifest = random_manifest(10)
    config = generic_config(manifest.name, batch_size)

    del config['etl'][0]["height"]

    with pytest.raises(RuntimeError) as ex:
        dl = DataLoader(config)
    assert 'height' in str(ex)
def test_loader_invalid_config_type():
    manifest = random_manifest(10)
    config = generic_config(manifest.name, batch_size)

    config["etl"][0]["type"] = 'invalid type name'

    with pytest.raises(RuntimeError) as ex:
        dl = DataLoader(config)
    assert 'unsupported' in str(ex)
Example #8
0
def test_loader_exception_next():
    # NOTE: manifest needs to stay in scope until DataLoader has read it.
    manifest = random_manifest(10, 2)
    config = generic_config(manifest.name)

    dl = DataLoader(config, gen_backend('cpu'))
    dl.next()
    with pytest.raises(LoaderRuntimeError):
        dl.next()
Example #9
0
def test_loader_missing_config_field():
    manifest = random_manifest(10)
    config = generic_config(manifest.name)

    del config['image']

    with pytest.raises(Exception) as ex:
        dl = DataLoader(config, gen_backend('cpu'))

    assert 'image' in str(ex)
Example #10
0
def test_loader_broken_image_next():
    manifest = random_manifest(9, broken_image_index=8)
    config = generic_config(manifest.name, batch_size)
    dl = DataLoader(config)

    with pytest.raises(Exception) as ex:
        for i in range(5):
            dl.next()
    assert 'Decoding image failed due to invalid data in the image file' in str(ex)

    dl2 = DataLoader(config)
    with pytest.raises(Exception) as ex:
        for data in dl2:
            pass
    assert 'Decoding image failed due to invalid data in the image file' in str(ex)