/usr/lib/python3/dist-packages/checkbox_ng/commands/test_cli.py is in python3-checkbox-ng 0.3.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | # This file is part of Checkbox.
#
# Copyright 2014 Canonical Ltd.
# Written by:
# Sylvain Pineau <sylvain.pineau@canonical.com>
#
# Checkbox is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3,
# as published by the Free Software Foundation.
#
# Checkbox is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Checkbox. If not, see <http://www.gnu.org/licenses/>.
"""
checkbox_ng.commands.test_cli
=============================
Test definitions for checkbox_ng.commands.cli module
"""
from unittest import TestCase
from plainbox.impl.job import JobOutputTextSource, JobDefinition
from plainbox.impl.secure.rfc822 import Origin
from plainbox.impl.secure.rfc822 import RFC822Record
from plainbox.impl.testing_utils import make_job
from checkbox_ng.commands.cli import SelectableJobTreeNode
class TestSelectableJobTreeNode(TestCase):
def setUp(self):
self.A = make_job('a', name='A')
self.B = make_job('b', name='B', plugin='local', description='foo')
self.C = make_job('c', name='C')
self.D = self.B.create_child_job_from_record(
RFC822Record(
data={'id': 'd', 'name': 'D', 'plugin': 'shell'},
origin=Origin(source=JobOutputTextSource(self.B),
line_start=1,
line_end=1)))
self.E = self.B.create_child_job_from_record(
RFC822Record(
data={'id': 'e', 'name': 'E', 'plugin': 'shell'},
origin=Origin(source=JobOutputTextSource(self.B),
line_start=1,
line_end=1)))
self.F = make_job('f', name='F', plugin='resource', description='baz')
self.tree = SelectableJobTreeNode.create_tree([
self.A,
self.B,
self.C,
self.D,
self.E,
self.F
], legacy_mode=True)
def test_create_tree(self):
self.assertIsInstance(self.tree, SelectableJobTreeNode)
self.assertEqual(len(self.tree.categories), 1)
[self.assertIsInstance(c, SelectableJobTreeNode)
for c in self.tree.categories]
self.assertEqual(len(self.tree.jobs), 2)
[self.assertIsInstance(j, JobDefinition) for j in self.tree.jobs]
self.assertTrue(self.tree.selected)
[self.assertTrue(self.tree.job_selection[j])
for j in self.tree.job_selection]
self.assertTrue(self.tree.expanded)
self.assertIsNone(self.tree.parent)
self.assertEqual(self.tree.depth, 0)
def test_get_node_by_index(self):
self.assertEqual(self.tree.get_node_by_index(0)[0].name, 'foo')
self.assertEqual(self.tree.get_node_by_index(1)[0].name, 'D')
self.assertEqual(self.tree.get_node_by_index(2)[0].name, 'E')
self.assertEqual(self.tree.get_node_by_index(3)[0].name, 'A')
self.assertEqual(self.tree.get_node_by_index(4)[0].name, 'C')
self.assertIsNone(self.tree.get_node_by_index(5)[0])
def test_render(self):
expected = ['[X] - foo',
'[X] D',
'[X] E',
'[X] A',
'[X] C']
self.assertEqual(self.tree.render(), expected)
def test_render_deselected_all(self):
self.tree.set_descendants_state(False)
expected = ['[ ] - foo',
'[ ] D',
'[ ] E',
'[ ] A',
'[ ] C']
self.assertEqual(self.tree.render(), expected)
def test_render_reselected_all(self):
self.tree.set_descendants_state(False)
self.tree.set_descendants_state(True)
expected = ['[X] - foo',
'[X] D',
'[X] E',
'[X] A',
'[X] C']
self.assertEqual(self.tree.render(), expected)
def test_render_with_child_collapsed(self):
self.tree.categories[0].expanded = False
expected = ['[X] + foo',
'[X] A',
'[X] C']
self.assertEqual(self.tree.render(), expected)
def test_set_ancestors_state(self):
self.tree.set_descendants_state(False)
node = self.tree.categories[0]
node.job_selection[self.E] = True
node.update_selected_state()
node.set_ancestors_state(node.selected)
expected = ['[X] - foo',
'[ ] D',
'[X] E',
'[ ] A',
'[ ] C']
self.assertEqual(self.tree.render(), expected)
node.selected = not(node.selected)
node.set_ancestors_state(node.selected)
node.set_descendants_state(node.selected)
expected = ['[ ] - foo',
'[ ] D',
'[ ] E',
'[ ] A',
'[ ] C']
self.assertEqual(self.tree.render(), expected)
def test_selection(self):
self.tree.set_descendants_state(False)
node = self.tree.categories[0]
node.job_selection[self.D] = True
node.update_selected_state()
node.set_ancestors_state(node.selected)
# Note that in addition to the selected (D) test, we need the
# tree selection to contain the resource (F), even though the
# user never saw it in the previous tests for visual presentation.
self.assertEqual(self.tree.selection, [self.D, self.F])
|