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
a34932b0
Commit
a34932b0
authored
3 years ago
by
Simon Rose
Browse files
Options
Downloads
Patches
Plain Diff
Rough refactor of test framework started, need at least two wrappers for this scenario
parent
cf66e6d1
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
tests/conftest.py
+43
-33
43 additions, 33 deletions
tests/conftest.py
tests/test_build.py
+4
-2
4 additions, 2 deletions
tests/test_build.py
tests/test_e3.py
+7
-4
7 additions, 4 deletions
tests/test_e3.py
tests/test_versions.py
+3
-2
3 additions, 2 deletions
tests/test_versions.py
with
57 additions
and
41 deletions
tests/conftest.py
+
43
−
33
View file @
a34932b0
...
...
@@ -7,34 +7,36 @@ from .utils import TEST_MODULE_NAME
@pytest.fixture
def
wrapper
(
tmpdir
,
request
):
"""
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
"""
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
=
"""
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
"""
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
=
"""
TOP:=$(CURDIR)
include $(REQUIRE_CONFIG)/CONFIG
include $(REQUIRE_CONFIG)/RULES_SITEMODS
"""
module_makefile
=
"""
module_makefile
=
"""
where_am_I := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
include $(E3_REQUIRE_TOOLS)/driver.makefile
...
...
@@ -44,16 +46,24 @@ DBDS += {dbds}
HEADERS += {headers}
"""
# 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
)
# 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
)
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
))
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
))
with
open
(
wrapper_dir
/
TEST_MODULE_PATH
/
"
test.dbd
"
,
"
w
"
)
as
f
:
pass
with
open
(
wrapper_dir
/
TEST_MODULE_PATH
/
"
test.dbd
"
,
"
w
"
)
as
f
:
pass
yield
wrapper_dir
return
wrapper_dir
yield
WrapperFactory
()
@pytest.fixture
def
wrapper
(
wrappers
):
yield
wrappers
.
get
()
This diff is collapsed.
Click to expand it.
tests/test_build.py
+
4
−
2
View file @
a34932b0
...
...
@@ -35,11 +35,12 @@ def create_patch_file(path, desc):
@pytest.mark.parametrize
(
"
wrapper
"
,
"
wrapper
s
"
,
[{
"
templates
"
:
"
database.db
"
}],
indirect
=
True
,
)
def
test_patch
(
wrapper
):
def
test_patch
(
wrappers
):
wrapper
=
wrappers
.
get
()
db_path
=
wrapper
/
TEST_MODULE_NAME
/
"
database.db
"
with
open
(
db_path
,
"
w
"
)
as
f
:
f
.
write
(
DB_FILE
)
...
...
@@ -106,6 +107,7 @@ def test_missing_source_file(wrapper):
def
test_missing_requirement
(
wrapper
):
print
(
wrapper
)
with
open
(
wrapper
/
f
"
{
TEST_MODULE_NAME
}
.Makefile
"
,
"
a
"
)
as
f
:
f
.
write
(
"
REQUIRED += foo
"
)
...
...
This diff is collapsed.
Click to expand it.
tests/test_e3.py
+
7
−
4
View file @
a34932b0
...
...
@@ -4,18 +4,20 @@ from .utils import run_make
@pytest.mark.parametrize
(
"
wrapper
"
,
"
wrapper
s
"
,
[{
"
E3_MODULE_SRC_PATH
"
:
"
test-loc
"
}],
indirect
=
True
,
)
def
test_loc
(
wrapper
):
def
test_loc
(
wrappers
):
wrapper
=
wrappers
.
get
()
rc
,
_
,
errs
=
run_make
(
wrapper
,
"
build
"
,
E3_MODULE_SRC_PATH
=
"
test-loc
"
)
assert
rc
==
2
assert
'
Local source mode
"
-loc
"
has been deprecated
'
in
errs
def
test_sitelibs
(
wrapper
):
def
test_sitelibs
(
wrapper
s
):
# Overwrite the default makefile
wrapper
=
wrappers
.
get
()
with
open
(
wrapper
/
"
Makefile
"
,
"
w
"
)
as
f
:
f
.
write
(
"""
...
...
@@ -37,7 +39,8 @@ include $(REQUIRE_CONFIG)/RULES_DEV
assert
"
RULES_E3 should only be loaded from RULES_SITEMODS
"
in
errs
def
test_incorrect_module_name
(
wrapper
):
def
test_incorrect_module_name
(
wrappers
):
wrapper
=
wrappers
.
get
()
module_name
=
"
ADCore
"
rc
,
_
,
errs
=
run_make
(
wrapper
,
"
build
"
,
E3_MODULE_NAME
=
module_name
)
assert
rc
==
2
...
...
This diff is collapsed.
Click to expand it.
tests/test_versions.py
+
3
−
2
View file @
a34932b0
...
...
@@ -9,7 +9,7 @@ RE_MODULE_NOT_LOADED = f"Module {TEST_MODULE_NAME} (not available|version {{requ
@pytest.mark.parametrize
(
"
wrapper
"
,
"
wrapper
s
"
,
[{
"
templates
"
:
""
,
"
sources
"
:
""
,
"
dbds
"
:
"
test.dbd
"
,
"
headers
"
:
""
}],
indirect
=
True
,
)
...
...
@@ -39,7 +39,8 @@ RE_MODULE_NOT_LOADED = f"Module {TEST_MODULE_NAME} (not available|version {{requ
(
""
,
"
0.1.0+0
"
,
[
"
0.1.0
"
,
"
1.0.0-rc1
"
]),
],
)
def
test_version
(
wrapper
,
requested
,
expected
,
installed
):
def
test_version
(
wrappers
,
requested
,
expected
,
installed
):
wrapper
=
wrappers
.
get
()
for
version
in
installed
:
returncode
,
_
,
_
=
run_make
(
wrapper
,
...
...
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