예제 #1
0
def test_rewind(output_dir):
    'test rewind calls base function and clear_output_dir'
    output_dir = os.path.join(output_dir, 'clear_test')
    r = Renderer(bna_sample, output_dir)
    bg_name = r.background_map_name
    fg_format = r.foreground_filename_format

    # dump some files into output dir:

    open(os.path.join(output_dir, bg_name), 'w').write('some junk')

    for i in range(5):
        open(os.path.join(output_dir,
             fg_format.format(i)),
             'w'
             ).write('some junk')

    now = datetime.now()
    r.prepare_for_model_run(model_start_time=now)

    assert r._model_start_time == now

    # prepare for model run clears output dir, but adds in the background map
    files = sorted(os.listdir(output_dir))
    assert files == sorted([os.path.basename(r.anim_filename),
                            r.background_map_name])

    r.rewind()

    # check super is called correctly
    assert r._model_start_time is None
    assert r._dt_since_lastoutput is None
    assert r._write_step is True

    # changed renderer and netcdf ouputter to delete old files in
    # prepare_for_model_run() rather than rewind()
    # -- rewind() was getting called a lot
    # -- before there was time to change the ouput file names, etc.
    # So for this unit test, there should only be a background image now.
    files = sorted(os.listdir(output_dir))
    assert files == sorted([os.path.basename(r.anim_filename),
                            r.background_map_name])
예제 #2
0
def test_rewind(output_dir):
    'test rewind calls base function and clear_output_dir'
    output_dir = os.path.join(output_dir, 'clear_test')
    r = Renderer(bna_sample, output_dir)
    bg_name = r.background_map_name
    fg_format = r.foreground_filename_format

    # dump some files into output dir:

    open(os.path.join(output_dir, bg_name), 'w').write('some junk')

    for i in range(5):
        open(os.path.join(output_dir,
             fg_format.format(i)),
             'w'
             ).write('some junk')

    now = datetime.now()
    r.prepare_for_model_run(model_start_time=now)

    assert r._model_start_time == now

    # prepare for model run clears output dir, but adds in the background map
    files = sorted(os.listdir(output_dir))
    assert files == sorted([os.path.basename(r.anim_filename),
                            r.background_map_name])

    r.rewind()

    # check super is called correctly
    assert r._model_start_time is None
    assert r._dt_since_lastoutput is None
    assert r._write_step is True

    # changed renderer and netcdf ouputter to delete old files in
    # prepare_for_model_run() rather than rewind()
    # -- rewind() was getting called a lot
    # -- before there was time to change the ouput file names, etc.
    # So for this unit test, there should only be a background image now.
    files = sorted(os.listdir(output_dir))
    assert files == sorted([os.path.basename(r.anim_filename),
                            r.background_map_name])
예제 #3
0
def test_file_delete(output_dir):

    output_dir = os.path.join(output_dir, 'clear_test')

    r = Renderer(bna_sample, output_dir)
    bg_name = r.background_map_name + "png"
    fg_format = r.foreground_filename_format

    # dump some files into output dir:
    open(os.path.join(output_dir, bg_name), 'w').write('some junk')

    for i in range(5):
        open(os.path.join(output_dir,
                          fg_format.format(i) + "png"), 'w').write('some junk')

    r.prepare_for_model_run(model_start_time=datetime.now())

    # The default output formats are ['png','gif']
    # so now there should only be a background image and the animated gif.
    files = sorted(os.listdir(output_dir))
    assert files == sorted(
        [os.path.basename(r.anim_filename), r.background_map_name + "png"])
예제 #4
0
def test_file_delete(output_dir):

    output_dir = os.path.join(output_dir, 'clear_test')

    r = Renderer(bna_sample, output_dir)
    bg_name = r.background_map_name
    fg_format = r.foreground_filename_format

    # dump some files into output dir:

    open(os.path.join(output_dir, bg_name), 'w').write('some junk')

    for i in range(5):
        open(os.path.join(output_dir, fg_format.format(i)), 'w'
             ).write('some junk')

    r.prepare_for_model_run(model_start_time=datetime.now())

    # The default output formats are ['png','gif']
    # so now there should only be a background image and the animated gif.
    files = sorted(os.listdir(output_dir))
    assert files == sorted([os.path.basename(r.anim_filename),
                            r.background_map_name])