Example #1
0
def test_always():
    def set_data(data):
        data['data'] = set_data.idx
        set_data.idx += 1
    set_data.idx = 0
    model = Reproducible("test_always")
    model.add_step(set_data, always = True)
    model.run()
    model.run()
    model.run()
    assert(model.data['data'] == 2)
Example #2
0
def test_real_step():
    def set_data(data):
        data['data'] = "hello"
    model = Reproducible("test3")
    model.add_step(set_data)
    model.run()
    assert(model.data['data'] == "hello")
Example #3
0
def test_pip_freeze():
    if os.path.exists('./data/test5'):
        shutil.rmtree('./data/test5')
    def set_data(data):
        data['data'] = "hello"
    model = Reproducible("test5", pipfreeze = True)
    model.add_step(set_data)
    model.run()
    assert(os.path.exists('data/test5/v0/requirements.txt'))
Example #4
0
def test_compare_steps():
    if os.path.exists('./data/test3'):
        shutil.rmtree('./data/test3')
    def set_data(data):
        data['data'] = "hello"
    model = Reproducible("test3")
    model.add_step(set_data)
    model.run()
    with tarfile.open('./data/test3/v0/set_data.tar', 'r') as f:
        assert(compare_steps(set_data, f))
Example #5
0
def test_multiple_steps():
    def set_data(data):
        if set_data.idx > 0:
            data['data'] = "uhoh!"
            return
        data['data'] = "hello"
        set_data.idx += 1
    set_data.idx = 0

    model = Reproducible("test4")
    model.add_step(set_data)
    model.run()
    assert(model.data['data'] == "hello")
    def set_more_data(data):
        data['stuff'] = "additional"
    model = Reproducible("test4")
    model.add_step(set_data)
    model.add_step(set_more_data)
    model.run()
    assert(model.data['data'] == "hello")
    assert(model.data['stuff'] == "additional")
Example #6
0
def test_new_fnc():
    def set_data(data):
        data['data'] = "hello"
    model = Reproducible("test5")
    model.add_step(set_data)
    model.run()
    def set_data(data):
        data['data'] = "goodbye"
    model = Reproducible("test5")
    model.add_step(set_data)
    model.run()
    assert(model.data['data'] == "goodbye")
Example #7
0
def test_initial():
    model = Reproducible("test1")
    model.run()
Example #8
0
def test_saved_step():
    def set_data(data):
        if set_data.idx > 0:
            data['data'] = "uhoh!"
            return
        data['data'] = "hello"
        set_data.idx += 1
    set_data.idx = 0

    model = Reproducible("test3")
    model.add_step(set_data)
    model.run()
    assert(model.data['data'] == "hello")

    model = Reproducible("test3")
    model.add_step(set_data)
    assert(not 'data' in model.data)
    model.run()
    assert(model.data['data'] == "hello")
Example #9
0
def test_data_directory():
    if os.path.exists('./data/test3'):
        shutil.rmtree('./data/test3')
    model = Reproducible("test3")
    assert(os.path.exists('./data/test3'))
Example #10
0
def test_new_fnc_new_directory():
    if os.path.exists('./data/test5'):
        shutil.rmtree('./data/test5')
    def set_data(data):
        data['data'] = "hello"
    model = Reproducible("test5")
    model.add_step(set_data)
    model.run()
    assert(os.path.exists('data/test5/v0'))
    def set_data(data):
        data['data'] = "goodbye"
    model = Reproducible("test5")
    model.add_step(set_data)
    model.run()
    assert(os.path.exists('data/test5/v1'))
    assert(model.data['data'] == "goodbye")
Example #11
0
def test_one_step():
    def do_nothing(model):
        pass
    model = Reproducible("test2")
    model.add_step(do_nothing)
    model.run()