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
a9e29965
Commit
a9e29965
authored
4 years ago
by
Jacob Wahlman
Browse files
Options
Downloads
Patches
Plain Diff
added check for overwrite, added more tests
parent
28dd5687
No related branches found
Branches containing commit
No related tags found
2 merge requests
!33
Resolve "Load/Save SFG to file"
,
!27
Resolve "Load/Save SFG to file"
Pipeline
#13971
passed
4 years ago
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
b_asic/utils.py
+7
-4
7 additions, 4 deletions
b_asic/utils.py
test/test_load_save_structure.py
+36
-7
36 additions, 7 deletions
test/test_load_save_structure.py
with
43 additions
and
11 deletions
b_asic/utils.py
+
7
−
4
View file @
a9e29965
...
...
@@ -20,15 +20,18 @@ def save_structure(struct: AbstractOperation, _path: Optional[str] = None, _name
Keyword Arguments:
_path: The path (str) to which the structure will be saved.
_name: The name (str) of the file to be saved. Only used if _path is
not defined and is not
None.
_name: The name (str) of the file to be saved. Only used if _path is None.
"""
try
:
_name
=
_name
if
_name
is
not
None
else
f
"
{
struct
.
type_name
}
.pickle
"
if
_path
is
None
:
_name
=
_name
if
_name
is
not
None
else
f
"
{
struct
.
type_name
}
.pickle
"
_path
=
path
.
join
(
getcwd
(),
_name
)
print
(
_path
)
index
=
1
while
path
.
exists
(
_path
):
_path
=
path
.
join
(
getcwd
(),
f
"
{
struct
.
type_name
}
(
{
index
}
).pickle
"
)
index
+=
1
with
open
(
_path
,
"
wb
"
)
as
handle
:
dill
.
dump
(
struct
,
handle
,
protocol
=
dill
.
HIGHEST_PROTOCOL
)
except
Exception
as
e
:
...
...
This diff is collapsed.
Click to expand it.
test/test_load_save_structure.py
+
36
−
7
View file @
a9e29965
from
os.path
import
isfile
"""
B-ASIC test suite for load/save datastructures.
"""
from
os
import
getcwd
,
path
from
random
import
choice
from
string
import
ascii_lowercase
import
pytest
...
...
@@ -9,15 +15,38 @@ class TestSaveStructures:
def
test_save_sfg
(
self
,
large_operation_tree
):
sfg
=
SFG
(
outputs
=
[
Output
(
large_operation_tree
)])
path
=
save_structure
(
sfg
)
assert
path
is
not
None
assert
isfile
(
path
)
_
path
=
save_structure
(
sfg
)
assert
_
path
is
not
None
assert
path
.
isfile
(
_
path
)
def
test_load_sfg
(
self
,
large_operation_tree
):
sfg
=
SFG
(
outputs
=
[
Output
(
large_operation_tree
)])
path
=
save_structure
(
sfg
)
_sfg
=
load_structure
(
path
)
_
path
=
save_structure
(
sfg
)
_sfg
=
load_structure
(
_
path
)
assert
isinstance
(
_sfg
,
SFG
)
assert
sorted
([
comp
.
type_name
for
comp
in
_sfg
.
components
])
==
sorted
([
comp
.
type_name
for
comp
in
sfg
.
components
])
assert
sfg
.
evaluate
()
==
_sfg
.
evaluate
()
def
test_save_invalid_path
(
self
,
large_operation_tree
):
sfg
=
SFG
(
outputs
=
[
Output
(
large_operation_tree
)])
_folder
=
""
.
join
(
choice
(
ascii_lowercase
)
for
_
in
range
(
4
))
while
path
.
exists
(
path
.
join
(
getcwd
(),
_folder
)):
_folder
=
""
.
join
(
choice
(
ascii_lowercase
)
for
_
in
range
(
4
))
_invalid_path
=
path
.
join
(
getcwd
(),
_folder
,
"
cool.pickle
"
)
_path
=
save_structure
(
sfg
,
_path
=
_invalid_path
)
assert
_path
is
None
def
test_load_invalid_path
(
self
,
large_operation_tree
):
_folder
=
""
.
join
(
choice
(
ascii_lowercase
)
for
_
in
range
(
4
))
while
path
.
exists
(
path
.
join
(
getcwd
(),
_folder
)):
_folder
=
""
.
join
(
choice
(
ascii_lowercase
)
for
_
in
range
(
4
))
_invalid_path
=
path
.
join
(
getcwd
(),
_folder
,
"
cool.pickle
"
)
_path
=
load_structure
(
_path
=
_invalid_path
)
assert
_path
is
None
\ 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