def setUp(self): self.config = testing.setUp() engine = create_engine('postgresql+psycopg2://thesis_db_user:[email protected]:5432/thesis_test_db') DBSession.configure(bind=engine) Base.metadata.create_all(engine) with transaction.manager: # Add TestLayer1 test_layer_1 = Layer(name='TestLayer1') test_layer_1.mappable_points = [ CachedGriddedAndBoundMappablePoint('Point(30 10)'), CachedGriddedAndBoundMappablePoint('Point(20 10)'), ] DBSession.add(test_layer_1) # Add TestLayer2 test_layer_2 = Layer(name='TestLayer2') test_layer_2.mappable_points = [ CachedGriddedAndBoundMappablePoint('Point(10 15)'), CachedGriddedAndBoundMappablePoint('Point(10 15)'), CachedGriddedAndBoundMappablePoint('Point(30 15)'), ] DBSession.add(test_layer_2) # Add Emu Layer tests_path = os.path.dirname(os.path.abspath(__file__)) test_fixtures_path = os.path.join(tests_path, 'fixtures') emu_csv_path = os.path.join(test_fixtures_path, 'emu.csv') emu_layer = Layer(name='Emu') with open(emu_csv_path, 'rb') as csvfile: emu_reader = csv.reader(csvfile) rownum = 0 header = None for row in emu_reader: # Save header row. if rownum == 0: header = row else: colnum = 0 latitude = 0 longitude = 0 for col in row: column_label = header[colnum] if column_label == "LNGDEC": longitude = col elif column_label == "LATDEC": latitude = col # print '%-8s: %s' % (column_label, col) colnum += 1 if longitude and latitude: mappable_point = CachedGriddedAndBoundMappablePoint('Point(%s %s)' % (longitude, latitude)) emu_layer.mappable_points.append(mappable_point) rownum += 1 DBSession.add(emu_layer) layers = DBSession.query(Layer).all() for layer in layers: CachedGriddedAndBoundMappablePoint.pre_process(layer)
def setUp(self): self.config = testing.setUp() engine = create_engine( "postgresql+psycopg2://thesis_db_user:[email protected]:5432/thesis_test_db" ) DBSession.configure(bind=engine) Base.metadata.create_all(engine) with transaction.manager: # Add TestLayer1 test_layer_1 = Layer(name="TestLayer1") test_layer_1.mappable_points = [MappablePoint("Point(30 10)"), MappablePoint("Point(20 10)")] DBSession.add(test_layer_1) # Add TestLayer2 test_layer_2 = Layer(name="TestLayer2") test_layer_2.mappable_points = [ MappablePoint("Point(10 15)"), MappablePoint("Point(10 15)"), MappablePoint("Point(30 15)"), ] DBSession.add(test_layer_2) # Add Emu Layer tests_path = os.path.dirname(os.path.abspath(__file__)) test_fixtures_path = os.path.join(tests_path, "fixtures") emu_csv_path = os.path.join(test_fixtures_path, "emu.csv") emu_layer = Layer(name="Emu") with open(emu_csv_path, "rb") as csvfile: emu_reader = csv.reader(csvfile) rownum = 0 header = None for row in emu_reader: # Save header row. if rownum == 0: header = row else: colnum = 0 latitude = 0 longitude = 0 for col in row: column_label = header[colnum] if column_label == "LNGDEC": longitude = col elif column_label == "LATDEC": latitude = col # print '%-8s: %s' % (column_label, col) colnum += 1 if longitude and latitude: mappable_point = MappablePoint("Point(%s %s)" % (longitude, latitude)) emu_layer.mappable_points.append(mappable_point) rownum += 1 DBSession.add(emu_layer)