Skip to content

Commit

Permalink
Added unit test to exercise load api
Browse files Browse the repository at this point in the history
- uses validated example of GTFS `sample-feed.zip`
  • Loading branch information
mgilligan committed Oct 30, 2013
1 parent 5a933b0 commit f462707
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 11 deletions.
3 changes: 2 additions & 1 deletion gtfsdb/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@


config = ConfigParser()
config.read(os.path.join(resource_filename('gtfsdb', 'configs'), 'app.ini'))
ini_file = os.path.join(resource_filename('gtfsdb', 'configs'), 'app.ini')
config.read(ini_file)
if config.has_section('loggers'):
logging.config.fileConfig(ini_file, disable_existing_loggers=False)
17 changes: 9 additions & 8 deletions gtfsdb/scripts/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,15 @@
log = logging.getLogger(__name__)


def load(filename, database_url='sqlite://', schema=None, is_geospatial=False):
'''Basic API to load a GTFS zip file'''
db = Database(database_url, schema, is_geospatial)
db.create()
gtfs = GTFS(filename)
gtfs.load(db)


def main():
# process command line args
parser = argparse.ArgumentParser(prog='gtfsdb-load',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('file', help='URL or local path to GTFS zip FILE')
Expand All @@ -19,13 +26,7 @@ def main():
parser.add_argument('--schema', default=None, help='Database SCHEMA name')
args = parser.parse_args()

# create database
db = Database(args.database_url, args.schema, args.is_geospatial)
db.create()

# load GTFS into database
gtfs = GTFS(args.file)
gtfs.load(db)
load(args.file, args.database_url, args.schema, args.is_geospatial)


if __name__ == '__main__':
Expand Down
2 changes: 0 additions & 2 deletions gtfsdb/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
# Need some useful tests here
from gtfsdb import *
Binary file added gtfsdb/tests/sample-feed.zip
Binary file not shown.
17 changes: 17 additions & 0 deletions gtfsdb/tests/test_load.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import os
from pkg_resources import resource_filename
import sys
if sys.version_info[:2] == (2, 6):
import unittest2 as unittest
else:
import unittest

from gtfsdb.scripts.load import load


class TestLoad(unittest.TestCase):

def test_load(self):
path = resource_filename('gtfsdb', 'tests')
filename = 'file:///{0}'.format(os.path.join(path, 'sample-feed.zip'))
load(filename)

0 comments on commit f462707

Please sign in to comment.