Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
e3-require
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Anders Lindh Olsson
e3-require
Commits
dabc8c1b
Commit
dabc8c1b
authored
3 years ago
by
Simon Rose
Browse files
Options
Downloads
Patches
Plain Diff
Trying to re-write conftest
parent
a34932b0
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/conftest.py
+46
-41
46 additions, 41 deletions
tests/conftest.py
with
46 additions
and
41 deletions
tests/conftest.py
+
46
−
41
View file @
dabc8c1b
from
pathlib
import
Path
from
random
import
choice
from
string
import
ascii_lowercase
import
pytest
from
git
import
Repo
from
.utils
import
TEST_MODULE_NAME
class
Wrapper
:
def
__init__
(
self
,
root_path
:
Path
,
name
=
None
,
include_dbd
=
True
,
**
kwargs
):
if
name
is
None
:
name
=
"
test_mod_
"
+
""
.
join
(
choice
(
ascii_lowercase
)
for
_
in
range
(
16
))
self
.
path
=
Path
(
root_path
/
f
"
e3-
{
name
}
"
)
self
.
name
=
name
@pytest.fixture
def
wrappers
(
tmpdir
,
request
):
class
WrapperFactory
:
def
get
(
self
):
"""
Sets up a wrapper with the minimal necessary configuration in order to build a module
module_path
=
(
name
if
"
E3_MODULE_SRC_PATH
"
not
in
kwargs
else
kwargs
[
"
E3_MODULE_SRC_PATH
"
]
)
self
.
module_dir
=
self
.
path
/
module_path
self
.
module_dir
.
mkdir
(
parents
=
True
)
Note that a number of necessary variables are expected to be present in the environment
"""
try
:
params
=
request
.
param
except
AttributeError
:
params
=
{}
wrapper_dir
=
Path
(
tmpdir
/
"
wrapper
"
)
TEST_MODULE_PATH
=
(
TEST_MODULE_NAME
if
"
E3_MODULE_SRC_PATH
"
not
in
params
else
params
[
"
E3_MODULE_SRC_PATH
"
]
)
test_dir
=
wrapper_dir
/
TEST_MODULE_PATH
test_dir
.
mkdir
(
parents
=
True
)
config_file
=
"""
self
.
makefile
=
self
.
path
/
f
"
{
name
}
.Makefile
"
makefile
=
f
"""
TOP:=$(CURDIR)
E3_MODULE_NAME:=
{
name
}
E3_MODULE_SRC_PATH:=
{
module_path
}
E3_MODULE_MAKEFILE:=
{
name
}
.Makefile
include $(REQUIRE_CONFIG)/CONFIG
include $(REQUIRE_CONFIG)/RULES_SITEMODS
"""
with
open
(
self
.
path
/
"
Makefile
"
,
"
w
"
)
as
f
:
f
.
write
(
makefile
)
module_makefile
=
"""
module_makefile
=
"""
where_am_I := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
include $(E3_REQUIRE_TOOLS)/driver.makefile
TEMPLATES += {templates}
SOURCES += {sources}
DBDS += {dbds}
HEADERS += {headers}
"""
with
open
(
self
.
path
/
f
"
{
name
}
.Makefile
"
,
"
w
"
)
as
f
:
f
.
write
(
module_makefile
)
# TODO: This should not be necessary, but it is for patching.
Repo
.
init
(
wrapper_dir
)
with
open
(
wrapper_dir
/
"
Makefile
"
,
"
w
"
)
as
f
:
f
.
write
(
config_file
)
if
include_dbd
:
self
.
add_file
(
"
test.dbd
"
)
make_vars
=
{
"
templates
"
:
""
,
"
sources
"
:
""
,
"
dbds
"
:
""
,
"
headers
"
:
""
}
make_vars
.
update
(
**
params
)
with
open
(
wrapper_dir
/
f
"
{
TEST_MODULE_NAME
}
.Makefile
"
,
"
w
"
)
as
f
:
f
.
write
(
module_makefile
.
format
(
**
make_vars
))
Repo
.
init
(
self
.
path
)
with
open
(
wrapper_dir
/
TEST_MODULE_PATH
/
"
test.dbd
"
,
"
w
"
)
as
f
:
pass
def
add_file
(
self
,
name
,
makefile_var
=
None
,
add_file
=
True
):
if
add_file
:
(
self
.
module_dir
/
name
).
touch
()
if
makefile_var
:
with
open
(
self
.
makefile
,
"
a
"
)
as
f
:
f
.
write
(
f
"
{
makefile_var
}
+=
{
name
}
"
)
return
wrapper_dir
@pytest.fixture
def
wrappers
(
tmpdir
,
request
):
class
WrapperFactory
:
def
get
(
self
):
"""
Sets up a wrapper with the minimal necessary configuration in order to build a module
Note that a number of necessary variables are expected to be present in the environment
"""
temp_wrapper
=
Wrapper
(
tmpdir
)
return
temp_wrapper
.
path
yield
WrapperFactory
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment