def test_get_data_dir_custom(conf_path): assert "KNOWHOW_DATA" not in os.environ app_dir = os.path.dirname(conf_path) data_dir = os.path.join(app_dir, "test_get_data_dir_custom") # create a conf file with an option in 'main' but no 'data' option with open(conf_path, "wb") as fh: fh.write(b"[main]\n") fh.write(b"data = ") fh.write(data_dir.encode("ascii")) fh.write(b"\n") assert conf.get_data_dir(app_dir=app_dir) == data_dir
def test_get_data_dir_default(conf_path): assert "KNOWHOW_DATA" not in os.environ app_dir = os.path.dirname(conf_path) # create a conf file with an option in 'main' but no 'data' option with open(conf_path, "wb") as fh: fh.write(b"[main]\n") fh.write(b"foo = bar\n") config = conf.get_config(app_dir=app_dir) # verify file is valid and we can read the option we added to main assert config.get("main", "foo") == "bar" # verify that reading data option handles error and uses default data_dir = conf.get_data_dir(app_dir=app_dir) assert data_dir == os.path.join(app_dir, "data")
def test_get_data_dir_env_set(): path = "/data" with env(KNOWHOW_DATA=path): assert conf.get_data_dir() == path
def test_get_data_dir_env_unset(conf_path): conf_dir = os.path.dirname(conf_path) with env(KNOWHOW_DATA=None, KNOWHOW_HOME=conf_dir): assert conf.get_data_dir() == "/app/data" assert conf.get_data_dir(app_dir=conf_dir) == "/app/data"
def __init__(self, app_dir=None, index_dir=None): self.app_dir = app_dir or conf.get_app_dir() self.index_dir = index_dir or conf.get_data_dir(app_dir=self.app_dir) self._whoosh_index = None