Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
irees committed Jan 24, 2023
1 parent f69ba8a commit 346a34e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 32 deletions.
5 changes: 2 additions & 3 deletions routetester/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def json(self):
}

class Checker(object):
def __init__(self, host=None, request_cls=None, request_factories=None, when=None, whentz=None, params=None, count=1):
def __init__(self, host=None, request_cls=None, request_factories=None, when=None, whentz=None, count=1):
self.host = host
self.request_factories = request_factories or []
if host and request_cls:
Expand All @@ -58,7 +58,6 @@ def __init__(self, host=None, request_cls=None, request_factories=None, when=Non
self.count = count
self.when = when
self.whentz = whentz
self.params = params

def load(self, testfile):
with open(testfile) as f:
Expand All @@ -77,7 +76,7 @@ def run(self):
for f in self.request_factories:
for _ in range(self.count):
request = f()
response = request.request(trip, params=self.params)
response = request.request(trip)
response.errors += TripMatcher().check(trip, response)
logging.info("%s -> %s"%(response.url, response.status_code))
self.rsets[trip].add_response(response)
Expand Down
2 changes: 1 addition & 1 deletion routetester/checkotp.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def url(self, trip, params=None):
}
if params:
q.update(params)
url = "%s/otp/routers/default/plan?%s"%(self.host, urlencode(q))
url = "%s/plan?%s"%(self.host, urlencode(q))
return url

def request(self, trip, params=None):
Expand Down
27 changes: 9 additions & 18 deletions routetester/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,9 @@ def main():
parser.add_argument('--when', help='Override all trip date/times, e.g. "next monday at 10am"')
parser.add_argument('--whentz', help='Timezone for --when')
parser.add_argument('-v', '--verbose', help='Print urls and failures', action='store_true')
parser.add_argument('-p', '--param', help='Add or override request parameter; example -p costing=auto', action='append')
parser.add_argument('--debug', action='store_true')
args = parser.parse_args()

# Set log level
level = logging.WARNING
if args.debug:
level = logging.DEBUG
elif args.verbose:
level = logging.INFO
logging.basicConfig(format='%(message)s', level=level)

# Check params
params = None
if args.param:
params = {}
for p in args.param:
key, _, value = p.partition("=")
params[key] = value

# Select planner
request_factories = []
i = 0
Expand All @@ -51,8 +34,16 @@ def main():
request_factories.append(functools.partial(request_cls, url))
i += 2

# Set log level
level = logging.WARNING
if args.debug:
level = logging.DEBUG
elif args.verbose:
level = logging.INFO
logging.basicConfig(format='%(message)s', level=level)

# Load tests
checker = Checker(request_factories=request_factories, when=args.when, whentz=args.whentz, params=params)
checker = Checker(request_factories=request_factories, when=args.when, whentz=args.whentz)
checker.load(args.testfile)
checker.run()
fc = checker.result_geojson()
Expand Down
11 changes: 1 addition & 10 deletions routetester/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ def main():
parser.add_argument('--debug', help='Print debug information', action='store_true')
parser.add_argument('-o', '--out', help='Save GeoJSON output to file')
parser.add_argument('-c', '--count', help='Run each test n times', default=1, type=int)
parser.add_argument('-p', '--param', help='Add or override request parameter; example -p costing=auto', action='append')
parser.add_argument('url', help='Test endpoint')
parser.add_argument('testfiles', nargs='+', help='Test GeoJSON input file')
args = parser.parse_args()
Expand All @@ -29,14 +28,6 @@ def main():
print("Unknown planner: %s"%args.mode)
sys.exit(1)

# Check params
params = None
if args.param:
params = {}
for p in args.param:
key, _, value = p.partition("=")
params[key] = value

# Set log level
level = logging.WARNING
if args.debug:
Expand All @@ -46,7 +37,7 @@ def main():
logging.basicConfig(format='%(message)s', level=level)

# Run checker
checker = Checker(args.url, request_cls, when=args.when, whentz=args.whentz, count=args.count, params=params)
checker = Checker(args.url, request_cls, when=args.when, whentz=args.whentz, count=args.count)
for filename in args.testfiles:
checker.load(filename)
checker.run()
Expand Down

0 comments on commit 346a34e

Please sign in to comment.