Skip to content

Commit 5d71390

Browse files
committedMar 19, 2018
Use expect_except (Python-3 compatibility)
1 parent 42b7ed6 commit 5d71390

File tree

1 file changed

+18
-25
lines changed

1 file changed

+18
-25
lines changed
 

‎_CNDB/_OMP/__test__/IP_Network.py

+18-25
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
# Copyright (C) 2013-2016 Mag. Christian Tanzer All rights reserved
2+
# Copyright (C) 2013-2018 Mag. Christian Tanzer All rights reserved
33
# Glasauergasse 32, A--1130 Wien, Austria. tanzer@swing.co.at
44
# #*** <License> ************************************************************#
55
# This module is part of the package CNDB.OMP.__test__.
@@ -53,6 +53,7 @@
5353
# have an associated `Net_Interface`.
5454
# 12-Mar-2015 (CT) Adapt to sqlalchemy 0.9.8
5555
# 12-Mar-2015 (CT) Fix backend dependent tests
56+
# 19-Mar-2018 (CT) Use `expect_except` (Python-3 compatibility)
5657
# ««revision-date»»···
5758
#--
5859

@@ -152,9 +153,8 @@
152153
10.0.64.0/18 Open Source Consulting : electric = T, children = F
153154
10.0.128.0/17 Open Source Consulting : electric = T, children = F
154155
155-
>>> ct_addr = osc_pool.reserve ('10.0.0.1/32', owner = ct)
156-
Traceback (most recent call last):
157-
...
156+
>>> with expect_except (CNDB.OMP.Error.Address_Already_Used) :
157+
... ct_addr = osc_pool.reserve ('10.0.0.1/32', owner = ct)
158158
Address_Already_Used: Address 10.0.0.1 already in use by 'Schlatterbeck Ralf'
159159
160160
>>> show_networks (scope, ETM, pool = rs_pool) ### 10.0.0.0/28
@@ -171,9 +171,8 @@
171171
10.0.0.4/30 Schlatterbeck Ralf : electric = T, children = F
172172
10.0.0.8/29 Schlatterbeck Ralf : electric = T, children = F
173173
174-
>>> ak_pool = rs_pool.allocate (28, ak)
175-
Traceback (most recent call last):
176-
...
174+
>>> with expect_except (CNDB.OMP.Error.No_Free_Address_Range) :
175+
... ak_pool = rs_pool.allocate (28, ak)
177176
No_Free_Address_Range: Address range [10.0.0.0/28] of this IP4_Network doesn't contain a free subrange for mask length 28
178177
179178
>>> show_networks (scope, ETM, pool = rs_pool) ### 10.0.0.0/30 ct after alloc error
@@ -210,14 +209,12 @@
210209
10.0.0.8/29 Glueck Martin : electric = F, children = F
211210
10.0.0.0/29 Schlatterbeck Ralf : electric = T, children = T
212211
213-
>>> xx_pool = rs_pool.allocate (30, mg)
214-
Traceback (most recent call last):
215-
...
212+
>>> with expect_except (CNDB.OMP.Error.No_Free_Address_Range) :
213+
... xx_pool = rs_pool.allocate (30, mg)
216214
No_Free_Address_Range: Address range [10.0.0.0/28] of this IP4_Network doesn't contain a free subrange for mask length 30
217215
218-
>>> yy_pool = mg_pool.allocate (29, mg)
219-
Traceback (most recent call last):
220-
...
216+
>>> with expect_except (CNDB.OMP.Error.No_Free_Address_Range) :
217+
... yy_pool = mg_pool.allocate (29, mg)
221218
No_Free_Address_Range: Address range [10.0.0.8/29] of this IP4_Network doesn't contain a free subrange for mask length 29
222219
223220
>>> show_network_count (scope, ETM)
@@ -398,13 +395,11 @@
398395
>>> q (Q.net_address.CONTAINS (n), sort_key = s).first ()
399396
CNDB.IP4_Network ("10.42.137.0/28")
400397
401-
>>> ff_pool.free ()
402-
Traceback (most recent call last):
403-
...
398+
>>> with expect_except (CNDB.OMP.Error.Cannot_Free_Network) :
399+
... ff_pool.free ()
404400
Cannot_Free_Network: Cannot free toplevel network 10.0.0.0/8
405-
>>> rs_pool.free ()
406-
Traceback (most recent call last):
407-
...
401+
>>> with expect_except (CNDB.OMP.Error.Cannot_Free_Network) :
402+
... rs_pool.free ()
408403
Cannot_Free_Network: Cannot free network with allocations: 10.0.0.0/28
409404
410405
>>> p1 = CNDB.IP4_Pool \\
@@ -799,15 +794,13 @@
799794
>>> xpool = CNDB.IP4_Network ('192.168.0.0/16', owner = ff, raw = True)
800795
>>> mgpool = xpool.allocate (17, mg)
801796
>>> ctpool = xpool.allocate (17, ct)
802-
>>> rspool = xpool.allocate (32, rs)
803-
Traceback (most recent call last):
804-
...
797+
>>> with expect_except (CNDB.OMP.Error.No_Free_Address_Range) :
798+
... rspool = xpool.allocate (32, rs)
805799
No_Free_Address_Range: Address range [192.168.0.0/16] of this IP4_Network doesn't contain a free subrange for mask length 32
806800
>>> ffpool = mgpool.allocate (22, ff)
807801
808-
>>> rspool = xpool.allocate (32, rs)
809-
Traceback (most recent call last):
810-
...
802+
>>> with expect_except (CNDB.OMP.Error.No_Free_Address_Range) :
803+
... rspool = xpool.allocate (32, rs)
811804
No_Free_Address_Range: Address range [192.168.0.0/16] of this IP4_Network doesn't contain a free subrange for mask length 32
812805
"""
813806

0 commit comments

Comments
 (0)
Please sign in to comment.