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
4212d8c8
Commit
4212d8c8
authored
3 years ago
by
Simon Rose
Browse files
Options
Downloads
Patches
Plain Diff
First draft of working refactor of wrapper mock class for tests
parent
dabc8c1b
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
tests/conftest.py
+2
-8
2 additions, 8 deletions
tests/conftest.py
tests/test_e3.py
+5
-11
5 additions, 11 deletions
tests/test_e3.py
tests/utils.py
+4
-4
4 additions, 4 deletions
tests/utils.py
with
11 additions
and
23 deletions
tests/conftest.py
+
2
−
8
View file @
4212d8c8
...
@@ -57,14 +57,8 @@ include $(E3_REQUIRE_TOOLS)/driver.makefile
...
@@ -57,14 +57,8 @@ include $(E3_REQUIRE_TOOLS)/driver.makefile
@pytest.fixture
@pytest.fixture
def
wrappers
(
tmpdir
,
request
):
def
wrappers
(
tmpdir
,
request
):
class
WrapperFactory
:
class
WrapperFactory
:
def
get
(
self
):
def
get
(
self
,
**
kwargs
):
"""
return
Wrapper
(
tmpdir
,
**
kwargs
)
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
()
yield
WrapperFactory
()
...
...
This diff is collapsed.
Click to expand it.
tests/test_e3.py
+
5
−
11
View file @
4212d8c8
import
pytest
from
.utils
import
run_make
from
.utils
import
run_make
@pytest.mark.parametrize
(
"
wrappers
"
,
[{
"
E3_MODULE_SRC_PATH
"
:
"
test-loc
"
}],
indirect
=
True
,
)
def
test_loc
(
wrappers
):
def
test_loc
(
wrappers
):
wrapper
=
wrappers
.
get
()
wrapper
=
wrappers
.
get
(
E3_MODULE_SRC_PATH
=
"
test-loc
"
)
rc
,
_
,
errs
=
run_make
(
wrapper
,
"
build
"
,
E3_MODULE_SRC_PATH
=
"
test-loc
"
)
rc
,
_
,
errs
=
run_make
(
wrapper
,
"
build
"
)
assert
rc
==
2
assert
rc
==
2
assert
'
Local source mode
"
-loc
"
has been deprecated
'
in
errs
assert
'
Local source mode
"
-loc
"
has been deprecated
'
in
errs
...
@@ -18,7 +11,7 @@ def test_loc(wrappers):
...
@@ -18,7 +11,7 @@ def test_loc(wrappers):
def
test_sitelibs
(
wrappers
):
def
test_sitelibs
(
wrappers
):
# Overwrite the default makefile
# Overwrite the default makefile
wrapper
=
wrappers
.
get
()
wrapper
=
wrappers
.
get
()
with
open
(
wrapper
/
"
Makefile
"
,
"
w
"
)
as
f
:
with
open
(
wrapper
.
path
/
"
Makefile
"
,
"
w
"
)
as
f
:
f
.
write
(
f
.
write
(
"""
"""
TOP:=$(CURDIR)
TOP:=$(CURDIR)
...
@@ -40,8 +33,9 @@ include $(REQUIRE_CONFIG)/RULES_DEV
...
@@ -40,8 +33,9 @@ include $(REQUIRE_CONFIG)/RULES_DEV
def
test_incorrect_module_name
(
wrappers
):
def
test_incorrect_module_name
(
wrappers
):
wrapper
=
wrappers
.
get
()
module_name
=
"
ADCore
"
module_name
=
"
ADCore
"
wrapper
=
wrappers
.
get
(
name
=
module_name
)
rc
,
_
,
errs
=
run_make
(
wrapper
,
"
build
"
,
E3_MODULE_NAME
=
module_name
)
rc
,
_
,
errs
=
run_make
(
wrapper
,
"
build
"
,
E3_MODULE_NAME
=
module_name
)
assert
rc
==
2
assert
rc
==
2
assert
f
"
E3_MODULE_NAME
'
{
module_name
}
'
is not valid
"
in
errs
assert
f
"
E3_MODULE_NAME
'
{
module_name
}
'
is not valid
"
in
errs
This diff is collapsed.
Click to expand it.
tests/utils.py
+
4
−
4
View file @
4212d8c8
...
@@ -40,14 +40,14 @@ def set_env_vars(env: dict) -> dict:
...
@@ -40,14 +40,14 @@ def set_env_vars(env: dict) -> dict:
return
env
return
env
def
run_make
(
path
,
*
args
,
**
kwargs
):
def
run_make
(
wrapper
,
*
args
,
**
kwargs
):
"""
"""
Attempt to run `make <args>` in the specified path with <kwargs> as environment variables
Attempt to run `make <args>` in the specified path with <kwargs> as environment variables
"""
"""
test_env
=
set_env_vars
(
os
.
environ
.
copy
())
test_env
=
set_env_vars
(
os
.
environ
.
copy
())
for
kw
in
kwargs
:
for
kw
in
kwargs
:
test_env
[
kw
]
=
kwargs
[
kw
]
test_env
[
kw
]
=
kwargs
[
kw
]
make_cmd
=
[
"
make
"
,
"
-C
"
,
path
]
+
list
(
args
)
make_cmd
=
[
"
make
"
,
"
-C
"
,
wrapper
.
path
]
+
list
(
args
)
p
=
subprocess
.
Popen
(
p
=
subprocess
.
Popen
(
make_cmd
,
make_cmd
,
stdout
=
subprocess
.
PIPE
,
stdout
=
subprocess
.
PIPE
,
...
@@ -59,11 +59,11 @@ def run_make(path, *args, **kwargs):
...
@@ -59,11 +59,11 @@ def run_make(path, *args, **kwargs):
return
p
.
returncode
,
outs
,
errs
return
p
.
returncode
,
outs
,
errs
def
get_env_var
(
path
,
var
:
str
):
def
get_env_var
(
wrapper
,
var
:
str
):
"""
"""
Fetch an environment variable from the module build environment
Fetch an environment variable from the module build environment
"""
"""
_
,
out
,
_
=
run_make
(
path
,
"
cellvars
"
)
_
,
out
,
_
=
run_make
(
wrapper
,
"
cellvars
"
)
for
line
in
out
.
split
(
"
\n
"
):
for
line
in
out
.
split
(
"
\n
"
):
if
line
.
startswith
(
var
):
if
line
.
startswith
(
var
):
return
line
.
split
(
"
=
"
)[
1
].
strip
()
return
line
.
split
(
"
=
"
)[
1
].
strip
()
...
...
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