Skip to content
This repository has been archived by the owner on May 18, 2023. It is now read-only.

Commit

Permalink
fix colcon test LINT errors (autowarefoundation#34)
Browse files Browse the repository at this point in the history
* Fix Q000 Double quotes found but single quotes preferred

* Fix Q000 Double quotes found but single quotes preferred

* Fix test_flake8 error of test_latency_viewer.py

* Pass flake8

* Pass flake8

* Pass flake8

* Fix flake8

* Fix flake8

* Fixing flake8

* Pass flake8

* Pass flake8

* Fix flake8

* Pass flake8

* Pass flake8

We change many files because of API change(print -> print_)

* Pass pep257

* Pass LINT

* Add tilde_vis_test README

* pre-commit fixes

Co-authored-by: pre-commit <pre-commit@example.com>
  • Loading branch information
y-okumura-isp and pre-commit authored Jun 7, 2022
1 parent 19c958b commit 319a4b6
Show file tree
Hide file tree
Showing 19 changed files with 909 additions and 593 deletions.
1 change: 1 addition & 0 deletions src/tilde_vis/setup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Visualization tool for TILDE."""
from setuptools import setup

package_name = 'tilde_vis'
Expand Down
112 changes: 58 additions & 54 deletions src/tilde_vis/test/test_data_as_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import unittest
from collections import deque
import unittest

from tilde_vis.data_as_tree import TreeNode


def dict2tree(adict):
"""Convert dictionary to TreeNode.
"""
Convert dictionary to TreeNode.
Parameters
----------
Expand All @@ -30,10 +31,11 @@ def dict2tree(adict):
Return
------
TreeNode starts from "root"
TreeNode starts from "root".
"""
Q = deque()
root = TreeNode("root")
root = TreeNode('root')
Q.append((root, adict))

while len(Q) > 0:
Expand All @@ -50,7 +52,8 @@ def dict2tree(adict):


def get_complex_tree():
"""Get complex tree.
"""
Get complex tree.
Return
------
Expand All @@ -59,20 +62,20 @@ def get_complex_tree():
So, call `ret.get_chile("p1")` and so on to access nodes.
"""
sample = {
"p1": {
"c1": "c11",
"c2": {
"c21": {
"c211": "c2111",
'p1': {
'c1': 'c11',
'c2': {
'c21': {
'c211': 'c2111',
},
"c22": "c221",
'c22': 'c221',
}
}
}

# (TreeNode, sub dictionary)
Q = deque()
root = TreeNode("root")
root = TreeNode('root')
Q.append((root, sample))

while len(Q) > 0:
Expand All @@ -90,20 +93,21 @@ def get_complex_tree():


class TestTreeNode(unittest.TestCase):

def test_construct(self):
node = TreeNode("foo")
node = TreeNode('foo')
self.assertTrue(node is not None)

def test_construct_complex(self):
root = get_complex_tree()

# check tree structure
self.assertEqual(len(root.children), 1)
p1 = root.name2child["p1"]
p1 = root.name2child['p1']
self.assertEqual(len(p1.children), 2)
c1 = p1.name2child["c1"]
c1 = p1.name2child['c1']
self.assertEqual(len(c1.children), 1)
c2 = p1.name2child["c2"]
c2 = p1.name2child['c2']
self.assertEqual(len(c2.children), 2)

def test_apply(self):
Expand All @@ -112,75 +116,75 @@ def test_apply(self):

self.assertEqual(len(ret), 10)
self.assertEqual(ret,
["root",
"p1",
"c1",
"c11",
"c2",
"c21",
"c211",
"c2111",
"c22",
"c221"])
['root',
'p1',
'c1',
'c11',
'c2',
'c21',
'c211',
'c2111',
'c22',
'c221'])

def test_apply_with_depth(self):
root = get_complex_tree()
ret = root.apply_with_depth(lambda n, depth: f"{n.name}_{depth}")
ret = root.apply_with_depth(lambda n, depth: f'{n.name}_{depth}')

self.assertEqual(len(ret), 10)
self.assertEqual(ret,
["root_0",
"p1_1",
"c1_2",
"c11_3",
"c2_2",
"c21_3",
"c211_4",
"c2111_5",
"c22_3",
"c221_4"])
['root_0',
'p1_1',
'c1_2',
'c11_3',
'c2_2',
'c21_3',
'c211_4',
'c2111_5',
'c22_3',
'c221_4'])

def test_merge(self):
lhs_dict = {
"c1": {
"c11": 1,
"c13": 2,
'c1': {
'c11': 1,
'c13': 2,
},
"c2": {
"c21": 3,
'c2': {
'c21': 3,
},
}
rhs_dict = {
"c1": {
"c11": 10,
"c12": {
"c121": 11,
'c1': {
'c11': 10,
'c12': {
'c121': 11,
},
},
"c2": 12,
'c2': 12,
}
lhs = dict2tree(lhs_dict)
rhs = dict2tree(rhs_dict)

def to_s(tree_node):
name = tree_node.name
data = tree_node.data
return f"{name}: {data}"
return f'{name}: {data}'

lhs.apply(lambda x: print(to_s(x)))
lhs.merge(rhs)
lhs.apply(lambda x: print(to_s(x)))

self.assertEqual(len(lhs.children), 2)
c1 = lhs.get_child("c1")
c1 = lhs.get_child('c1')
self.assertEqual(len(c1.children), 3)
self.assertEqual(c1.get_child("c11").data, [1, 10])
self.assertEqual(c1.get_child("c12").get_child("c121").data, [11])
self.assertEqual(c1.get_child("c13").data, [2])
self.assertEqual(c1.get_child('c11').data, [1, 10])
self.assertEqual(c1.get_child('c12').get_child('c121').data, [11])
self.assertEqual(c1.get_child('c13').data, [2])

c2 = lhs.get_child("c2")
c2 = lhs.get_child('c2')
self.assertEqual(c2.data, [12])
self.assertEqual(c2.get_child("c21").data, [3])
self.assertEqual(c2.get_child('c21').data, [3])


if __name__ == '__main__':
Expand Down
Loading

0 comments on commit 319a4b6

Please sign in to comment.