Commit a2588b98 authored by Samuel GAIST's avatar Samuel GAIST

[test] Initialise all databases root_folder

This will allow to use them in the same temporary
folder used for other test data.
parent 1d93c335
......@@ -35,6 +35,7 @@
# Basic setup for slow tests
import json
import logging
import os
import shutil
......@@ -44,8 +45,6 @@ import tempfile
import pkg_resources
from beat.backend.python.test import BBP_DATABASE_ROOT_FOLDER
if sys.platform == "darwin":
tmp_prefix = tempfile.mkdtemp(
prefix=__name__, suffix=".tmpdir", dir="/tmp" # nosec
......@@ -58,10 +57,10 @@ else:
prefix_folder = tempfile.mkdtemp(prefix=__name__, suffix=".prefix")
BC_DATABASE_ROOT_FOLDER = "/tmp/beat_core_test" # nosec
prefix = os.path.join(prefix_folder, "prefix")
BC_DATABASE_ROOT_FOLDER = os.path.join(prefix_folder, "beat_core_test")
DOCKER_NETWORK_TEST_ENABLED = (
os.environ.get("DOCKER_NETWORK_TEST_ENABLED", False) == "True"
)
......@@ -97,8 +96,22 @@ def setup_package():
for path in prefixes:
sp.check_call(["rsync", "-arz", path, prefix_folder])
for path in [BBP_DATABASE_ROOT_FOLDER, BC_DATABASE_ROOT_FOLDER]:
os.makedirs(path, exist_ok=True)
os.makedirs(BC_DATABASE_ROOT_FOLDER, exist_ok=True)
for root, dirs, files in os.walk(os.path.join(prefix, "databases"), topdown=False):
for file_ in files:
if file_.endswith(".json"):
path = os.path.join(root, file_)
try:
with open(path, "rt") as db_file:
declaration = json.load(db_file)
except json.JSONDecodeError:
# some are explicitly invalid.
continue
else:
declaration["root_folder"] = BC_DATABASE_ROOT_FOLDER
with open(path, "wt") as db_file:
json.dump(declaration, db_file, indent=4)
if DOCKER_NETWORK_TEST_ENABLED:
import docker
......@@ -124,8 +137,7 @@ def teardown_package():
if os.path.exists(tmp_prefix):
shutil.rmtree(tmp_prefix)
for path in [prefix_folder, BBP_DATABASE_ROOT_FOLDER, BC_DATABASE_ROOT_FOLDER]:
shutil.rmtree(path)
shutil.rmtree(prefix_folder)
if DOCKER_NETWORK_TEST_ENABLED:
global network
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment