Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B-ASIC - Better ASIC Toolbox
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package 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
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Computer Engineering
B-ASIC - Better ASIC Toolbox
Commits
62f421c4
Commit
62f421c4
authored
4 years ago
by
Jacob Wahlman
Browse files
Options
Downloads
Patches
Plain Diff
added tests for recipes and definition
parent
4c4164ed
No related branches found
Branches containing commit
No related tags found
1 merge request
!33
Resolve "Load/Save SFG to file"
Pipeline
#14092
failed
4 years ago
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
b_asic/utils.py
+11
-0
11 additions, 0 deletions
b_asic/utils.py
test/test_load_save_structure.py
+36
-2
36 additions, 2 deletions
test/test_load_save_structure.py
with
47 additions
and
2 deletions
b_asic/utils.py
+
11
−
0
View file @
62f421c4
...
...
@@ -54,3 +54,14 @@ def load_structure(_path: str) -> AbstractOperation:
print
(
"
Unexpected error occured while loading structure:
"
,
e
)
return
None
def
load_recipe
(
module
:
str
)
->
None
:
"""
Given the module name or the path to a module, import the module and let it evaluate it
'
s content.
Returns None as the content from the module will be added to the namespace.
This runs .py scripts inline by importing them, it currently does no checks for security measure.
Arguments:
module: The path or name of the module to import from.
"""
pass
This diff is collapsed.
Click to expand it.
test/test_load_save_structure.py
+
36
−
2
View file @
62f421c4
...
...
@@ -8,7 +8,7 @@ from string import ascii_lowercase
import
pytest
from
b_asic
import
SFG
,
Output
,
load_structure
,
save_structure
from
b_asic
import
SFG
,
Output
,
load_structure
,
save_structure
,
load_recipe
class
TestSaveStructures
:
...
...
@@ -50,4 +50,38 @@ class TestSaveStructures:
_path
=
load_structure
(
_path
=
_invalid_path
)
assert
_path
is
None
\ No newline at end of file
def
test_load_recipe_file
(
self
):
# Create a file that doesn't exist
_file
=
""
.
join
(
choice
(
ascii_lowercase
)
for
_
in
range
(
4
))
+
"
.py
"
while
path
.
exists
(
path
.
join
(
getcwd
(),
_file
)):
_file
=
""
.
join
(
choice
(
ascii_lowercase
)
for
_
in
range
(
4
))
+
"
.py
"
try
:
with
open
(
_file
,
"
w+
"
)
as
handle
:
# The string is indented that way so the file is properly indented, .strip() did not work idk why
handle
.
write
(
"""
from b_asic import SFG, Output, Addition, Constant
sfg = SFG(outputs=[Output(Addition(Addition(Constant(2), Constant(3)), Addition(Constant(4), Constant(5))))])
"""
)
except
Exception
as
e
:
assert
False
,
f
"
Could not create file:
{
e
}
"
# Not defined yet
with
pytest
.
raises
(
NameError
):
sfg
.
evaluate
()
==
14
load_recipe
(
_file
)
assert
sfg
.
evaluate
()
==
14
def
test_load_invalid_recipe_file
(
self
):
_file
=
""
.
join
(
choice
(
ascii_lowercase
)
for
_
in
range
(
4
))
+
"
.py
"
while
path
.
exists
(
path
.
join
(
getcwd
(),
_file
)):
_file
=
""
.
join
(
choice
(
ascii_lowercase
)
for
_
in
range
(
4
))
+
"
.py
"
load_recipe
(
_file
)
with
pytest
.
raises
(
NameError
):
assert
sfg
.
evaluate
()
==
14
\ No newline at end of file
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