Skip to content

Commit

Permalink
allow totalstations.py to get arguments for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
TNick committed May 6, 2017
1 parent 834a9f7 commit e146845
Showing 1 changed file with 49 additions and 14 deletions.
63 changes: 49 additions & 14 deletions totalstations.py
Expand Up @@ -920,19 +920,54 @@ def parse_next(self):
"""
unit test
"""
ts = Idex('samples/test.idx')
#ts = Dump('samples/xxx.dmp')
#ts = SurvCE('samples/EBO-1739.rw5')
#ts = Stonex('samples/PAJE2OB.DAT')
#ts = LeicaGsi('samples/tata3.gsi', ' ')
#ts = JobAre('samples/test1.job', '=')
#ts = Sdr('samples/PAJE04.crd', None)
import sys
import os

if len(sys.argv) > 1:
# maps extensions to classes; first item in list is the class
# and second, if present, is second argument for class
# constructor
ext2class = {
'.idx': [Idex],
'.dmp': [Dump],
'.rw5': [SurvCE],
'.dat': [Stonex],
'.gsi': [LeicaGsi, ' '],
'.job': [JobAre, '='],
'.crd': [Sdr, None]
}
# find the class
try:
toexec = ext2class[os.path.splitext(sys.argv[1])[1].lower()]
except KeyError:
print 'Unknown extension for file', sys.argv[1]
sys.exit(1)

if len(sys.argv) == 3:
# the user may provide an argument to pass to the class
ts = toexec[0](sys.argv[1], sys.argv[2])
elif len(toexec) == 1:
# no default for second argument
ts = toexec[0](sys.argv[1])
else:
# there is a default second argument
ts = toexec[0](sys.argv[1], toexec[1])
else:
ts = Idex('samples/test.idx')
#ts = Dump('samples/xxx.dmp')
#ts = SurvCE('samples/EBO-1739.rw5')
#ts = Stonex('samples/PAJE2OB.DAT')
#ts = LeicaGsi('samples/tata3.gsi', ' ')
#ts = JobAre('samples/test1.job', '=')
#ts = Sdr('samples/PAJE04.crd', None)

if ts.open() != 0:
print "Open error"
while True:
r = ts.parse_next()
if r is None:
break
if len(r) > 0:
print r
ts.close()
else:
while True:
r = ts.parse_next()
if r is None:
break
if len(r) > 0:
print r
ts.close()

0 comments on commit e146845

Please sign in to comment.