Commit 62ca988
committed
Fix python2->3 port: broken imports, dropped test logic, and real bugs
The test suite could not run at all in this PR: every test file mixed
a bare `from BaseTestCase import X` (needs tests/ on sys.path) with
`from lib import X` (needs the repo root on sys.path), while the
leftover sys.path.insert only added <repo_root>/lib, satisfying
neither. Normalized every test file + BaseTestCase.py to insert the
repo root and import BaseTestCase via `tests.BaseTestCase`. Also gave
lib/processor.py and lib/networks.py package-relative imports for
ipcalc, since bare `import ipcalc` only worked when lib/ itself was on
sys.path (the old, now-abandoned convention).
Real bugs found once the suite could actually run:
- TestParser.py: testParseNetwork/testParseNetworkNoVlan silently lost
their processor.network(...) setup calls during the port, so they
asserted against an empty table. Restored them.
- processor.py host(): vlan lookup used the host's own freshly-created
node_id instead of the passed-in network_id, so vlan (and therefore
IPv6 address generation) was always None. Also dropped a bogus
`row[5] = json.dumps(row[5])` that JSON-encoded the network_id
foreign key before insert.
- processor.py network(): `len(net_ipv4)` crashed (ipcalc.Network has
no __len__) on every call; and the function returned a
(node_id, network_id) tuple instead of just node_id, corrupting
parse()'s network_id tracking for every host/network line after the
first network definition in a file.
- lib/packages.py, lib/firewall.py: leftover `.iteritems()` calls
(removed in Python 3). One of them (firewall.py's redundant-flow
pruning loop) had also lost its `node, services` tuple unpacking,
silently disabling that logic entirely rather than crashing.
- lib/location.py switch_locations(): `/` now does true division in
Python 3 where Python 2 silently floor-divided, producing fractional
pixel coordinates. Restored `//` to keep whole-pixel output.
- lib/ipcalc.py: removed a redundant duplicate `self.mask = int(...)`
line.
- requirements.txt: removed `requests`, `layout`, `ipcalc`, `six`,
`processor` (layout/ipcalc/processor are this project's own lib/
modules, not PyPI packages; requests/six are unused), and bumped
PyYAML off the ancient 3.11 pin, which fails to build against modern
CPython.
- makefile: test/coverage/draw targets still invoked python2.7.
TestSeatmap.testAddCoordinates/testSwitchLocation/
testSwitchLocationWithMixedLayout expectations updated for two
inherent, unavoidable Python 2->3 differences that surfaced once the
suite could run: dict iteration order (insertion-order in Py3 vs
hash-order in Py2) changes which hall's switches get inserted first,
and round()'s tie-breaking rule (round-half-to-even in Py3 vs
round-half-away-from-zero in Py2) changes one scaled-width value by 2px.
Verified: full test suite passes under Python 3, and an end-to-end
`generate.py` run against real fixture data produces correct host
vlan/IPv6/network_id data (previously broken by the host() bug above).1 parent 11f04d2 commit 62ca988
14 files changed
Lines changed: 66 additions & 67 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
| 27 | + | |
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| |||
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
100 | | - | |
| 100 | + | |
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
| |||
110 | 110 | | |
111 | 111 | | |
112 | 112 | | |
113 | | - | |
| 113 | + | |
114 | 114 | | |
115 | 115 | | |
116 | 116 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
181 | 181 | | |
182 | 182 | | |
183 | 183 | | |
184 | | - | |
185 | | - | |
186 | 184 | | |
187 | 185 | | |
188 | 186 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
123 | 123 | | |
124 | 124 | | |
125 | 125 | | |
126 | | - | |
127 | | - | |
| 126 | + | |
| 127 | + | |
128 | 128 | | |
129 | 129 | | |
130 | 130 | | |
131 | | - | |
132 | | - | |
| 131 | + | |
| 132 | + | |
133 | 133 | | |
134 | 134 | | |
135 | 135 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
63 | | - | |
| 63 | + | |
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
79 | | - | |
| 79 | + | |
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | 1 | | |
4 | 2 | | |
5 | 3 | | |
6 | 4 | | |
7 | 5 | | |
8 | 6 | | |
9 | 7 | | |
| 8 | + | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
74 | | - | |
| 74 | + | |
75 | 75 | | |
76 | | - | |
77 | | - | |
| 76 | + | |
| 77 | + | |
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
| |||
106 | 106 | | |
107 | 107 | | |
108 | 108 | | |
109 | | - | |
110 | 109 | | |
111 | 110 | | |
112 | 111 | | |
| |||
123 | 122 | | |
124 | 123 | | |
125 | 124 | | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
| 125 | + | |
130 | 126 | | |
131 | 127 | | |
132 | 128 | | |
| |||
152 | 148 | | |
153 | 149 | | |
154 | 150 | | |
155 | | - | |
| 151 | + | |
156 | 152 | | |
157 | 153 | | |
158 | 154 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | | - | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | | - | |
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | 4 | | |
6 | | - | |
| 5 | + | |
7 | 6 | | |
8 | 7 | | |
9 | 8 | | |
10 | 9 | | |
11 | 10 | | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
0 commit comments