# -*- coding: utf-8 -*- from json import loads from os import listdir from os.path import dirname, abspath, join, normpath, splitext # import warnings # from tiramisu.error import ValueWarning from tiramisu_json_api import Config # warnings.simplefilter("always", ValueWarning) def list_data(): datadir = join(normpath(dirname(abspath(__file__))), 'data') filenames = listdir(datadir) filenames.sort() for filename in filenames: if filename.endswith('.json'): yield join(datadir, filename) def test_dict(): debug = False # debug = True for filename in list_data(): if 'master' in filename: continue if debug: print('test_jsons', filename) with open(filename, 'r') as fh: json = loads(fh.read()) # config = Config(json) with open(filename[:-4] + 'dict', 'r') as fh: assert loads(fh.read()) == config.value.dict() def test_get(): for filename in list_data(): if 'master' in filename: continue with open(filename, 'r') as fh: json = loads(fh.read()) config = Config(json) with open(filename[:-4] + 'dict', 'r') as fh: dico = loads(fh.read()) for key, value in dico.items(): assert value == config.option(key).value.get() def test_owner(): for filename in list_data(): if 'master' in filename: continue with open(filename, 'r') as fh: json = loads(fh.read()) config = Config(json) with open(filename[:-4] + 'owner', 'r') as fh: dico = loads(fh.read()) for key, value in dico.items(): assert value == config.option(key).owner.get() def test_prop(): for filename in list_data(): if 'master' in filename: continue with open(filename, 'r') as fh: json = loads(fh.read()) config = Config(json) with open(filename[:-4] + 'prop', 'r') as fh: dico = loads(fh.read()) for key, value in dico.items(): props = set(config.option(key).property.get()) if 'clearable' in props: props.remove('clearable') assert set(value) == props, 'error in {}'.format(filename) def test_prop2(): for filename in list_data(): if 'master' in filename: continue with open(filename, 'r') as fh: json = loads(fh.read()) config = Config(json) with open(filename[:-4] + 'prop2', 'r') as fh: dico = loads(fh.read()) for key, value in dico.items(): props = set(config.option(key).property.get(True)) assert set(value) == props, 'error in {}'.format(filename) def test_info(): for filename in list_data(): if 'master' in filename: continue with open(filename, 'r') as fh: json = loads(fh.read()) config = Config(json) with open(filename[:-4] + 'info', 'r') as fh: dico = loads(fh.read()) for key, values in dico.items(): for info, value in values.items(): if info == 'type' and value in ['filename', 'ip', 'email', 'username']: continue assert getattr(config.option(key).option, info)() == value, 'error for {} in {}'.format(info, filename)