forked from Riverscapes/pyBRAT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tests.py
45 lines (37 loc) · 1.26 KB
/
Tests.py
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
# -------------------------------------------------------------------------------
# Name: Tests
# Purpose: Contains a number of tests to check for bugs in the code
#
# Author: Braden Anderson
#
# Created: 06/2018
# -------------------------------------------------------------------------------
import arcpy
class TestException(Exception):
pass
def test_reach_id_is_unique(network):
"""
Makes sure that the Reach ID is unique
:param network: The network to test
:return:
"""
reach_ids = []
with arcpy.da.SearchCursor(network, ['ReachID']) as cursor:
for row in cursor:
reach_id = row[0]
if reach_id in reach_ids:
raise TestException("Multiple reaches have a ReachID of " + str(reach_id))
reach_ids.append(reach_id)
def report_exceptions(exceptions):
"""
Reports the exceptions found during testing
:param exceptions: The list of exceptions found during testing
:return:
"""
if len(exceptions) == 0:
arcpy.AddMessage("All tests passed")
else:
arcpy.AddMessage("The following exceptions were raised during testing:")
for exception in exceptions:
arcpy.AddError(exception)
arcpy.AddMessage("")