def test_load_empty_json(self): path = os.path.join(mocks.constants.MOCKS_PATHS, 'options_empty.json') settings = Settings(path) settings.init() assert settings.start_date is None assert settings.output_type is None assert settings.output_path == settings.default_output_path assert settings.tickers == []
def wrapped(self_, *args, **kwargs): settings = Settings(SETTINGS_PATH) settings.init() component = component_class(settings) return method(self_, component, *args, settings=settings, **kwargs)
def test_set_defaults_no_components(self): # No components initialized, so 'from_file' should fail explicitly # and raise a bunch of exceptions with pytest.raises(exceptions.MissingSourceHandlersException): s = Settings(mocks.constants.SETTINGS_PATH) s.init() manager.register_handlers_from_obj(finra) with pytest.raises(exceptions.MissingWritersException): s = Settings(mocks.constants.SETTINGS_PATH) s.init()
def start(): os.system('clear') settings = Settings() if settings.init(): click.echo("Settings loaded") else: click.echo("There was an error Loading the settings") entry.run(settings)
def test_settings_serialize(self): settings = Settings(mocks.constants.SETTINGS_PATH) assert settings.init() is True with open(mocks.constants.SETTINGS_PATH) as file: data = json.loads(file.read()) out = settings.serialize() assert data == out
def test_settings_init(self): wrong_default_path = './not/a/file.json' settings = Settings(wrong_default_path) wrong_path_2 = "./another/wrong/path.json" expected_errors = [ 'Settings FILE not found at ./another/wrong/path.json', 'Settings FILE not found at ./not/a/file.json' ] # should cause initialization with default values # (file not found or wrong) assert settings.init(wrong_path_2) is True assert settings.init_done is True assert settings.start_date is None assert settings.errors == expected_errors assert settings.init(mocks.constants.SETTINGS_PATH) is True assert settings.init_done is True validate_start_date(settings)
def test_settings_tofile(self): settings = Settings(mocks.constants.SETTINGS_PATH) assert settings.init() is True settings.to_file(mocks.constants.TEMP_JSON_FILE) with open(mocks.constants.SETTINGS_PATH) as file: original = json.loads(file.read()) with open(mocks.constants.TEMP_JSON_FILE) as file: out = json.loads(file.read()) assert original == out
def test_init(self): # Test normal behaviour with a correct file s1 = Settings(mocks.constants.SETTINGS_PATH) s1.init() assert s1.init_done is True assert s1.start_date == utils.get_expected_start_date() # Test with wrong provided path but with a valid default one s2 = Settings("./not/a/path.json") s2.settings_path = mocks.constants.SETTINGS_PATH s2.init() assert s2.init_done is True assert s1.start_date == utils.get_expected_start_date() # Test with either files missing or wrong paths s3 = Settings("./not/a/path.json") s3.settings_path = "./default/not/path.json" s3.init() assert s3.init_done is True assert s3.start_date is None
def getApp(init=True): settings = Settings(mocks.constants.SETTINGS_PATH) if init: settings.init() return App(settings)