Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
finam
Manage
Activity
Members
Labels
Plan
Issues
31
Issue boards
Milestones
Code
Merge requests
3
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
FINAM
finam
Commits
d6a48a27
Commit
d6a48a27
authored
2 years ago
by
Martin Lange
Browse files
Options
Downloads
Patches
Plain Diff
add a check to avoid giving infos that already have rules
parent
6f3b8395
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!154
Auto-transfer infos
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/finam/tools/connect_helper.py
+19
-4
19 additions, 4 deletions
src/finam/tools/connect_helper.py
tests/tools/test_connect.py
+29
-6
29 additions, 6 deletions
tests/tools/test_connect.py
with
48 additions
and
10 deletions
src/finam/tools/connect_helper.py
+
19
−
4
View file @
d6a48a27
...
...
@@ -111,7 +111,7 @@ class ConnectHelper(Loggable):
with
ErrorLogger
(
self
.
logger
):
for
name
in
pull_data
or
[]:
if
name
not
in
self
.
_inputs
:
raise
Value
Error
(
raise
Key
Error
(
f
"
No input named
'
{
name
}
'
available to get info for.
"
)
...
...
@@ -273,6 +273,7 @@ class ConnectHelper(Loggable):
with
ErrorLogger
(
self
.
logger
):
self
.
_check_names
(
exchange_infos
,
push_infos
,
push_data
)
self
.
_check_in_rules
(
exchange_infos
,
push_infos
)
exchange_infos
=
{
k
:
v
for
k
,
v
in
exchange_infos
.
items
()
if
self
.
in_infos
[
k
]
is
None
...
...
@@ -359,15 +360,29 @@ class ConnectHelper(Loggable):
def
_check_names
(
self
,
exchange_infos
,
push_infos
,
push_data
):
for
name
in
exchange_infos
:
if
name
not
in
self
.
_inputs
:
raise
Value
Error
(
raise
Key
Error
(
f
"
No input named
'
{
name
}
'
available to exchange info for.
"
)
for
name
in
push_infos
:
if
name
not
in
self
.
_outputs
:
raise
Value
Error
(
f
"
No output named
'
{
name
}
'
available to push info.
"
)
raise
Key
Error
(
f
"
No output named
'
{
name
}
'
available to push info.
"
)
for
name
in
push_data
:
if
name
not
in
self
.
_outputs
:
raise
ValueError
(
f
"
No output named
'
{
name
}
'
available to push data.
"
)
raise
KeyError
(
f
"
No output named
'
{
name
}
'
available to push data.
"
)
def
_check_in_rules
(
self
,
exchange_infos
,
push_infos
):
for
name
in
exchange_infos
:
if
name
in
self
.
_in_info_rules
:
raise
ValueError
(
f
"
There are info transfer rules given for input `
{
name
}
`.
"
f
"
Can
'
t provide the info directly.
"
)
for
name
in
push_infos
:
if
name
in
self
.
_out_info_rules
:
raise
ValueError
(
f
"
There are info transfer rules given for output `
{
name
}
`.
"
f
"
Can
'
t provide the info directly.
"
)
def
_exchange_in_infos
(
self
):
any_done
=
False
...
...
This diff is collapsed.
Click to expand it.
tests/tools/test_connect.py
+
29
−
6
View file @
d6a48a27
...
...
@@ -119,16 +119,16 @@ class TestConnectHelper(unittest.TestCase):
outputs
.
add
(
name
=
"
Out1
"
)
outputs
.
add
(
name
=
"
Out2
"
)
with
self
.
assertRaises
(
Value
Error
):
with
self
.
assertRaises
(
Key
Error
):
_connector
=
ConnectHelper
(
"
TestLogger
"
,
inputs
,
outputs
,
pull_data
=
[
"
In3
"
])
connector
=
ConnectHelper
(
"
TestLogger
"
,
inputs
,
outputs
)
with
self
.
assertRaises
(
Value
Error
):
with
self
.
assertRaises
(
Key
Error
):
connector
.
connect
(
time
=
None
,
exchange_infos
=
{
"
In3
"
:
Info
(
time
,
NoGrid
())})
with
self
.
assertRaises
(
Value
Error
):
with
self
.
assertRaises
(
Key
Error
):
connector
.
connect
(
time
=
None
,
push_infos
=
{
"
Out3
"
:
Info
(
time
,
NoGrid
())})
with
self
.
assertRaises
(
Value
Error
):
with
self
.
assertRaises
(
Key
Error
):
connector
.
connect
(
time
=
None
,
push_data
=
{
"
Out3
"
:
0.0
})
def
test_connect_caching
(
self
):
...
...
@@ -320,8 +320,7 @@ class TestConnectHelper(unittest.TestCase):
{
"
Out1
"
:
Info
(
time
=
time
,
grid
=
UniformGrid
((
10
,
10
)),
units
=
"
m
"
)},
)
def
test_connect_transfer_fail
(
self
):
def
test_connect_constructor_fail
(
self
):
inputs
=
IOList
(
None
,
"
INPUT
"
)
inputs
.
add
(
name
=
"
In1
"
)
outputs
=
IOList
(
None
,
"
OUTPUT
"
)
...
...
@@ -366,3 +365,27 @@ class TestConnectHelper(unittest.TestCase):
outputs
,
in_info_rules
=
{
"
In1
"
:
[
0
]},
)
def
test_connect_rules_fail
(
self
):
inputs
=
IOList
(
None
,
"
INPUT
"
)
inputs
.
add
(
name
=
"
In1
"
)
outputs
=
IOList
(
None
,
"
OUTPUT
"
)
outputs
.
add
(
name
=
"
Out1
"
)
connector
:
ConnectHelper
=
ConnectHelper
(
"
TestLogger
"
,
inputs
,
outputs
,
in_info_rules
=
{
"
In1
"
:
[
FromOutput
(
"
Out1
"
)]},
out_info_rules
=
{
"
Out1
"
:
[
FromInput
(
"
In1
"
)]},
)
with
self
.
assertRaises
(
ValueError
):
connector
.
connect
(
time
=
None
,
exchange_infos
=
{
"
In1
"
:
Info
(
time
=
None
,
grid
=
NoGrid
())}
)
with
self
.
assertRaises
(
ValueError
):
connector
.
connect
(
time
=
None
,
push_infos
=
{
"
Out1
"
:
Info
(
time
=
None
,
grid
=
NoGrid
())}
)
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