Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
beat
beat.core
Commits
67a4e0d0
Commit
67a4e0d0
authored
Nov 10, 2020
by
Samuel GAIST
Browse files
[test] Refactor initialization to make it more reusable
beat/beat.cmdline re-implements similar parts so make them reusable
parent
1492e907
Pipeline
#45200
passed with stage
in 25 minutes and 14 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
beat/core/test/__init__.py
View file @
67a4e0d0
...
...
@@ -59,8 +59,6 @@ else:
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"
)
...
...
@@ -87,18 +85,15 @@ if VERBOSE_TEST_LOGGING:
logger
.
addHandler
(
handler
)
def
setup_package
():
prefixes
=
[
pkg_resources
.
resource_filename
(
"beat.backend.python.test"
,
"prefix"
),
pkg_resources
.
resource_filename
(
"beat.core.test"
,
"prefix"
),
]
def
sync_prefixes
(
source_prefixes
,
target_prefix
):
for
path
in
source_prefixes
:
sp
.
check_call
([
"rsync"
,
"-arz"
,
path
,
target_prefix
])
for
path
in
prefixes
:
sp
.
check_call
([
"rsync"
,
"-arz"
,
path
,
prefix_folder
])
os
.
makedirs
(
BC_DATABASE_ROOT_FOLDER
,
exist_ok
=
True
)
def
initialize_db_root_folder
(
database_root_folder
,
databases_path
):
os
.
makedirs
(
database_root_folder
,
exist_ok
=
True
)
for
root
,
dirs
,
files
in
os
.
walk
(
os
.
path
.
join
(
prefix
,
"
databases
"
)
,
topdown
=
False
):
for
root
,
dirs
,
files
in
os
.
walk
(
databases
_path
,
topdown
=
False
):
for
file_
in
files
:
if
file_
.
endswith
(
".json"
):
path
=
os
.
path
.
join
(
root
,
file_
)
...
...
@@ -109,10 +104,24 @@ def setup_package():
# some are explicitly invalid.
continue
else
:
declaration
[
"root_folder"
]
=
BC_DATABASE_ROOT_FOLDER
declaration
[
"root_folder"
]
=
database_root_folder
with
open
(
path
,
"wt"
)
as
db_file
:
json
.
dump
(
declaration
,
db_file
,
indent
=
4
)
def
setup_package
():
sync_prefixes
(
[
pkg_resources
.
resource_filename
(
"beat.backend.python.test"
,
"prefix"
),
pkg_resources
.
resource_filename
(
"beat.core.test"
,
"prefix"
),
],
prefix_folder
,
)
initialize_db_root_folder
(
os
.
path
.
join
(
prefix_folder
,
"beat_core_test"
),
os
.
path
.
join
(
prefix
,
"databases"
)
)
if
DOCKER_NETWORK_TEST_ENABLED
:
import
docker
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment