Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pycomsdk
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
com
pycomsdk
Commits
ed60c72e
Commit
ed60c72e
authored
Apr 15, 2025
by
Sergey Bobrov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Unit тест последовательного графа
parent
bb7c1772
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
128 additions
and
0 deletions
+128
-0
simplest.py
test_funcs/simplest.py
+3
-0
cycled.adot
tests/test_aDOT/test_adot_files/cycled.adot
+0
-0
sequential.adot
tests/test_aDOT/test_adot_files/sequential.adot
+18
-0
unit_test_aDOT.py
tests/test_aDOT/unit_test_aDOT.py
+107
-0
No files found.
test_funcs/simplest.py
View file @
ed60c72e
...
...
@@ -4,6 +4,9 @@ def dummy_edge(data):
def
increment_a_edge
(
data
):
data
[
'a'
]
+=
1
def
increment_a_double
(
data
):
data
[
'a'
]
*=
2
def
increment_a_array_edge
(
data
):
for
i
in
range
(
len
(
data
[
'a'
])):
data
[
'a'
][
i
]
+=
1
...
...
tests/test_aDOT/test_adot_files/cycled.adot
0 → 100644
View file @
ed60c72e
tests/test_aDOT/test_adot_files/sequential.adot
0 → 100644
View file @
ed60c72e
digraph SEQUENTIAL_TEST {
// Функции-обработчики
INCREMENT [module=test_funcs.simplest, entry_func=increment_a_edge, comment = func_INCREMENT]
DOUBLE [module=test_funcs.simplest, entry_func=increment_a_double, comment = func_DOUBLE]
// Функции-предикаты
ALWAYS_TRUE [module=test_funcs.simplest, entry_func=true_predicate, comment = pred_ALWAYS_TRUE]
// Морфизмы
EDGE_1 [predicate=ALWAYS_TRUE, function=INCREMENT, comment = edge_1]
EDGE_2 [predicate=ALWAYS_TRUE, function=DOUBLE, comment = edge_2]
// Граф
__BEGIN__ -> STEP_1 [morphism=EDGE_1]
STEP_1 -> STEP_2 [morphism=EDGE_2]
STEP_2 -> __END__
}
\ No newline at end of file
tests/test_aDOT/unit_test_aDOT.py
0 → 100644
View file @
ed60c72e
import
unittest
import
os
from
comsdk.parser
import
Parser
from
comsdk.graph
import
Graph
class
TestADOTParser
(
unittest
.
TestCase
):
@classmethod
def
setUpClass
(
cls
):
cls
.
test_files_dir
=
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
"test_adot_files"
)
cls
.
parser
=
Parser
()
def
test_sequential_graph
(
self
):
"""Тест последовательного графа"""
graph
=
self
.
parser
.
parse_file
(
os
.
path
.
join
(
self
.
test_files_dir
,
"sequential.adot"
))
self
.
assertIsInstance
(
graph
,
Graph
)
# Проверка структуры
init_state
=
graph
.
init_state
self
.
assertEqual
(
len
(
init_state
.
transfers
),
1
)
# Проверка выполнения
data
=
{
"a"
:
1
}
result
=
graph
.
run
(
data
)
self
.
assertTrue
(
result
)
self
.
assertEqual
(
data
[
"a"
],
4
)
# 1 -> (inc) 2 -> (double) 4
def
test_cycled_graph
(
self
):
"""Тест циклического графа"""
graph
=
self
.
parser
.
parse_file
(
os
.
path
.
join
(
self
.
test_files_dir
,
"cycled.adot"
))
self
.
assertIsInstance
(
graph
,
Graph
)
# Проверка выполнения с ограничением
data
=
{
"value"
:
0
,
"limit"
:
5
}
result
=
graph
.
run
(
data
)
self
.
assertTrue
(
result
)
self
.
assertEqual
(
data
[
"value"
],
5
)
def
test_branching_graph
(
self
):
"""Тест графа с ветвлениями"""
graph
=
self
.
parser
.
parse_file
(
os
.
path
.
join
(
self
.
test_files_dir
,
"branching.adot"
))
self
.
assertIsInstance
(
graph
,
Graph
)
# Проверка ветвления A
data
=
{
"condition"
:
True
}
result
=
graph
.
run
(
data
)
self
.
assertTrue
(
result
)
self
.
assertTrue
(
data
[
"processed_by_a"
])
# Проверка ветвления B
data
=
{
"condition"
:
False
}
result
=
graph
.
run
(
data
)
self
.
assertTrue
(
result
)
self
.
assertTrue
(
data
[
"processed_by_b"
])
def
test_subgraph_integration
(
self
):
"""Тест интеграции подграфов"""
graph
=
self
.
parser
.
parse_file
(
os
.
path
.
join
(
self
.
test_files_dir
,
"subgraph.adot"
))
self
.
assertIsInstance
(
graph
,
Graph
)
data
=
{}
result
=
graph
.
run
(
data
)
self
.
assertTrue
(
result
)
self
.
assertTrue
(
data
[
"preprocessed"
])
self
.
assertTrue
(
data
[
"postprocessed"
])
def
test_edge_types
(
self
):
"""Тест разных типов ребер (-> и =>)"""
graph
=
self
.
parser
.
parse_file
(
os
.
path
.
join
(
self
.
test_files_dir
,
"edge_types.adot"
))
self
.
assertIsInstance
(
graph
,
Graph
)
transfers
=
graph
.
init_state
.
transfers
self
.
assertEqual
(
transfers
[
0
]
.
edge
.
order
,
0
)
# ->
self
.
assertEqual
(
transfers
[
1
]
.
edge
.
order
,
1
)
# =>
def
test_attributes_parsing
(
self
):
"""Тест парсинга атрибутов узлов и ребер"""
graph
=
self
.
parser
.
parse_file
(
os
.
path
.
join
(
self
.
test_files_dir
,
"attributes.adot"
))
# Проверка атрибутов состояния
state
=
graph
.
init_state
self
.
assertEqual
(
state
.
parallelization_policy
.
__class__
.
__name__
,
"ThreadParallelizationPolicy"
)
self
.
assertIsNotNone
(
state
.
selector
)
self
.
assertEqual
(
state
.
comment
,
"Test node with attributes"
)
# Проверка атрибутов ребра
edge
=
state
.
transfers
[
0
]
.
edge
self
.
assertEqual
(
edge
.
comment
,
"Test edge with attributes"
)
class
TestGraphExecution
(
unittest
.
TestCase
):
def
test_parallel_execution
(
self
):
"""Тест параллельного выполнения"""
# Здесь должны быть тесты реального параллельного выполнения
# с использованием threading/multiprocessing
pass
def
test_error_handling
(
self
):
"""Тест обработки ошибок"""
parser
=
Parser
()
with
self
.
assertRaises
(
Exception
):
parser
.
parse_file
(
os
.
path
.
join
(
"test_adot_files"
,
"invalid_syntax.adot"
))
if
__name__
==
'__main__'
:
unittest
.
main
()
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment