Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SpiderMQTT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
fxk8y
SpiderMQTT
Commits
01f4f8fb
Commit
01f4f8fb
authored
2 years ago
by
fxk8y
Browse files
Options
Downloads
Patches
Plain Diff
Moar testing stuff…
parent
65320d73
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
DeltaMatcher.py
+70
-0
70 additions, 0 deletions
DeltaMatcher.py
TopicMatcherTest.py
+17
-6
17 additions, 6 deletions
TopicMatcherTest.py
with
87 additions
and
6 deletions
DeltaMatcher.py
0 → 100644
+
70
−
0
View file @
01f4f8fb
# bool SubscriberMeta::matches(const std::string &other_topic, const std::vector<std::string> &other_topic_split) {
# // TODO: block subscriptions for invalid topics
#
# if(this->topic == "#")
# return true;
#
# // if(other_topic_split.size() == this->topic_split.size() - 1)
# // if((other_topic + "/#") == this->topic)
# // return true;
#
# for(u32 i = 0; i < this->topic_split.size(); i++) {
# auto &p = this->topic_split.at(i);
#
# if(p == "#")
# return true;
#
# if(p == "+")
# continue;
#
# if(p != other_topic_split.at(i))
# return false;
# }
#
# if(this->topic_split.size() == other_topic_split.size())
# return true;
#
# if(this->topic_split.at(this->topic_split.size() - 1) == "#")
# return true;
#
# return false;
# }
def
get
(
l
:
list
,
idx
:
int
):
if
idx
>=
0
and
idx
<
len
(
l
):
return
l
[
idx
]
else
:
return
None
def
matches
(
topic
,
otherTopic
)
->
bool
:
if
topic
==
'
#
'
:
return
True
topicSplit
=
topic
.
split
(
'
/
'
)
otherTopicSplit
=
otherTopic
.
split
(
'
/
'
)
for
i
in
range
(
len
(
topicSplit
)):
p
=
get
(
topicSplit
,
i
)
if
p
==
'
#
'
:
return
True
if
p
==
'
+
'
:
continue
if
p
!=
get
(
otherTopicSplit
,
i
):
return
False
if
len
(
topicSplit
)
==
len
(
otherTopicSplit
):
return
True
# if get(topicSplit, len(topicSplit) - 2) == '#':
# return True
return
False
This diff is collapsed.
Click to expand it.
TopicMatcherTest.py
+
17
−
6
View file @
01f4f8fb
...
...
@@ -2,6 +2,7 @@
#!nix-shell -i python -p "python3.withPackages(ps : with ps; [ pyyaml paho-mqtt ])"
import
DeltaMatcher
from
cProfile
import
run
from
SpiderMQTT
import
Topic
...
...
@@ -40,15 +41,25 @@ topicsNotMatching = [
]
def
runTest
(
t0
:
str
,
t1
:
str
,
expectation
:
bool
):
testFunc
=
Topic
.
compare
# testFunc = DeltaMatcher.matches
result
=
Topic
.
compare
(
t0
,
t1
)
==
expectation
expStr
=
'
==
'
if
expectation
else
'
!=
'
resultSym
=
'
✅
'
if
result
else
'
❌
'
resultStr
=
'
PASSED
'
if
result
else
'
FAILED
'
def
runTest
(
t0
:
str
,
t1
:
str
,
expectation
:
bool
,
swapInputs
:
bool
=
False
):
print
(
f
'
[
{
resultSym
}
] Test: [
{
t0
}
]
{
expStr
}
[
{
t1
}
]
{
resultStr
}
'
)
def
_test
(
t0
:
str
,
t1
:
str
):
result
=
testFunc
(
t0
,
t1
)
==
expectation
expStr
=
'
==
'
if
expectation
else
'
!=
'
resultSym
=
'
✅
'
if
result
else
'
❌
'
resultStr
=
'
PASSED
'
if
result
else
'
FAILED
'
print
(
f
'
[
{
resultSym
}
] Test: [
{
t0
}
]
{
expStr
}
[
{
t1
}
]
{
resultStr
}
'
)
_test
(
t0
,
t1
)
if
swapInputs
:
_test
(
t1
,
t0
)
def
runTestGroup
(
group
:
list
,
expectation
:
bool
):
...
...
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