示例#1
0
def test_gen_dir(tmpdir):
    with open(example_filename('test_settings.dat'), encoding='utf-8') as f:
        settings = Settings.load_from(f)

    with io.StringIO() as f:
        generate_csv(f, [basedir], settings=settings, outdir=str(tmpdir))
        got = f.getvalue()
    assert_dirs_same(str(tmpdir), os.path.join(basedir, 'expected_dir'))
示例#2
0
def test_gen_csv_cs(lang):
    with open(example_filename('test_settings.dat')) as f:
        settings = Settings.load_from(f)
    settings.lang = lang

    with io.StringIO() as f:
        generate_csv(f, [basedir], settings=settings)
        got = f.getvalue()
    with open(os.path.join(basedir, 'expected_{}.csv'.format(lang))) as f:
        expected = f.read()
    assert got == expected
def check_roundtrip(settings):
    first = io.StringIO()
    first_dict = settings.to_dict()
    settings.save_to(first)

    f = io.StringIO(first.getvalue())
    read_settings = Settings.load_from(f)

    second_dict = settings.to_dict()

    assert first_dict == second_dict
    assert json.loads(first.getvalue()) == first_dict
示例#4
0
def test_gen_csv_cs(lang):
    with open(example_filename('test_settings.dat'), encoding='utf-8') as f:
        settings = Settings.load_from(f)
    settings.lang = lang

    with io.StringIO() as f:
        generate_csv(f, [basedir], settings=settings)
        got = f.getvalue()

    with open(os.path.join(basedir, 'expected_{}.csv'.format(lang)),
            encoding='utf-8') as expected_f:

        with io.StringIO(got) as got_f:
            assert_csv_same(got_f, expected_f)
示例#5
0
def open_analyzer(test_file_name):
    settings = Settings()
    settings.model_version = 1
    with open(os.path.join(basedir, test_file_name), 'rb') as f:
        analyzer = ImageAnalyzer(f, settings=settings)
    return analyzer
def test_deserialization_default():
    with open(example_filename('default_settings.dat')) as f:
        settings = Settings.load_from(f)
    assert_settings_equal(settings, Settings())
def test_load_messed_up_old():
    with open(example_filename('messed_up_old_settings.dat')) as f:
        settings = Settings.load_from(f)
    with open(example_filename('messed_up_settings.dat')) as f:
        control = Settings.load_from(f)
    assert_settings_equal(settings, control)
def test_load_old():
    with open(example_filename('old_settings.dat')) as f:
        settings = Settings.load_from(f)
    control = Settings()
    control.model_version = 1
    assert_settings_equal(settings, control)