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
c7b98e1d
Commit
c7b98e1d
authored
Apr 03, 2025
by
Sergey Bobrov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Добавил комментарий в graph.py
parent
87ece5bb
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
106 additions
and
5 deletions
+106
-5
README.md
README.md
+0
-0
graph.py
comsdk/graph.py
+9
-0
parser.py
comsdk/parser.py
+1
-0
cycled_v2.adot
tests/adot/cycled_v2.adot
+10
-5
node_attrs.adot
tests/test_adot_files/node_attrs.adot
+11
-0
test_parser.py
tests/test_parser.py
+75
-0
No files found.
README.md
View file @
c7b98e1d
comsdk/graph.py
View file @
c7b98e1d
...
...
@@ -92,6 +92,15 @@ class Graph:
self
.
term_state
.
is_term_state
=
True
self
.
_initialized
=
False
def
__repr__
(
self
):
return
(
f
"Graph(
\n
"
f
" init_state={self.init_state!r},
\n
"
f
" term_state={self.term_state!r},
\n
"
f
" initialized={self._initialized}
\n
"
f
")"
)
def
run
(
self
,
data
):
'''
Goes through the graph and returns boolean denoting whether the graph has finished successfully.
...
...
comsdk/parser.py
View file @
c7b98e1d
...
...
@@ -320,6 +320,7 @@ class Parser():
checked
=
[]
bushes
=
{}
selectorends
=
{}
def
generate_cpp
(
self
,
filename
=
None
):
self
.
fact
.
graph
.
init_state
.
input_edges_number
=
0
states_to_check
=
[
self
.
fact
.
graph
.
init_state
]
...
...
tests/adot/cycled_v2.adot
View file @
c7b98e1d
digraph CYCLIC {
// Функции и предикаты
INC [module="math_ops", entry_func="increment"]
CHECK [module="checks", entry_func="less_than_3"]
MORPH_LOOP [predicate=CHECK, function=INC]
// Селектор для узла LOOP
SEL_LOOP [module="selectors", entry_func="check_iterations"]
// Объявление функций
FUNC [module=test_funcs.simplest, entry_func=decrement_a_edge]
PRED [module=test_funcs.simplest, entry_func=true_predicate]
MORPH_LOOP [predicate=PRED, function=FUNC]
MORPH_EXIT [function=INC]
// Топология с циклом
LOOP [selector=SEL_LOOP] # Привязка селектора к узлу
// Топология
__BEGIN__ -> LOOP [edge_index=0]
LOOP -> LOOP [morphism=MORPH_LOOP, edge_index=1]
LOOP -> __END__ [morphism=MORPH_EXIT, edge_index=2]
...
...
tests/test_adot_files/node_attrs.adot
0 → 100644
View file @
c7b98e1d
digraph Test {
__BEGIN__ -> NODE_1
NODE_1 [
selector=MY_SELECTOR,
subgraph="subgraph.adot",
parallelism=threading,
comment="Test node with attributes"
]
NODE_1 -> __END__
}
\ No newline at end of file
tests/test_parser.py
View file @
c7b98e1d
...
...
@@ -8,6 +8,80 @@ from comsdk.parser import Parser
path_to_comsdk
=
"/home/lbstr/bmstu/comsdk"
path_to_pycomsdk
=
"/home/lbstr/bmstu/pycomsdk"
class
TestAdvancedParser
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
test_files_dir
=
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
"test_adot_files"
)
def
test_node_attributes_parsing
(
self
):
"""Проверка парсинга атрибутов узлов"""
parser
=
Parser
()
graph
=
parser
.
parse_file
(
os
.
path
.
join
(
self
.
test_files_dir
,
"node_attrs.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"
)
def
test_edge_types_parsing
(
self
):
"""Проверка обработки разных типов ребер"""
parser
=
Parser
()
graph
=
parser
.
parse_file
(
os
.
path
.
join
(
self
.
test_files_dir
,
"edge_types.adot"
))
# Проверка обычного и многопоточного ребер
transfers
=
graph
.
init_state
.
transfers
self
.
assertEqual
(
transfers
[
0
]
.
edge
.
order
,
0
)
# ->
self
.
assertEqual
(
transfers
[
1
]
.
edge
.
order
,
1
)
# =>
def
test_subgraph_parsing
(
self
):
"""Тестирование встраивания подграфов"""
parser
=
Parser
()
graph
=
parser
.
parse_file
(
os
.
path
.
join
(
self
.
test_files_dir
,
"subgraph_test.adot"
))
# Проверка замены состояния подграфом
state
=
graph
.
init_state
self
.
assertTrue
(
hasattr
(
state
,
"_proxy_state"
))
self
.
assertEqual
(
len
(
state
.
_proxy_state
.
transfers
),
2
)
def
test_keys_mapping
(
self
):
"""Проверка преобразования ключей"""
parser
=
Parser
()
graph
=
parser
.
parse_file
(
os
.
path
.
join
(
self
.
test_files_dir
,
"keys_mapping.adot"
))
# Проверка настроек ключей для обработчика
edge
=
graph
.
init_state
.
transfers
[
0
]
.
edge
self
.
assertEqual
(
edge
.
_io_mapping
.
_keys_mapping
[
"local_key"
],
"global.key.path"
)
def
test_config_integration
(
self
):
"""Интеграция с внешними конфигурационными файлами"""
parser
=
Parser
()
graph
=
parser
.
parse_file
(
os
.
path
.
join
(
self
.
test_files_dir
,
"config_integration.adot"
))
# Проверка загрузки параметров из конфига
func
=
graph
.
init_state
.
transfers
[
0
]
.
edge
.
morph_f
self
.
assertEqual
(
func
.
module
,
"configured_module"
)
self
.
assertEqual
(
func
.
name
,
"configured_function"
)
def
test_error_handling
(
self
):
"""Проверка обработки ошибок"""
parser
=
Parser
()
with
self
.
assertRaises
(
Exception
)
as
context
:
parser
.
parse_file
(
os
.
path
.
join
(
self
.
test_files_dir
,
"invalid_syntax.adot"
))
self
.
assertIn
(
"Syntax error"
,
str
(
context
.
exception
))
def
test_pre_post_processors
(
self
):
"""Тестирование пре- и пост-процессоров"""
parser
=
Parser
()
graph
=
parser
.
parse_file
(
os
.
path
.
join
(
self
.
test_files_dir
,
"pre_post_processors.adot"
))
edge
=
graph
.
init_state
.
transfers
[
0
]
.
edge
self
.
assertIsNotNone
(
edge
.
preprocess
)
self
.
assertIsNotNone
(
edge
.
postprocess
)
class
ParserGoodCheck
(
unittest
.
TestCase
):
...
...
@@ -17,6 +91,7 @@ class ParserGoodCheck(unittest.TestCase):
# Проверка загрузки файла
self
.
assertTrue
(
os
.
path
.
exists
(
"./adot/trivial_v2.adot"
))
gr
=
parsr
.
parse_file
(
"./adot/trivial_v2.adot"
)
print
(
gr
)
# Основной сценарий
data
=
{
"a"
:
1
}
...
...
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