def test_archive_postgres(tmpdir, testdata): pguser = os.environ.get('PGUSER') pgpassword = os.environ.get('PGPASSWORD') id = pyroSAR.identify(testdata['s1']) db = pyroSAR.Archive('test', postgres=True, port=5432, user=pguser, password=pgpassword) db.insert(testdata['s1'], verbose=False) assert all(isinstance(x, str) for x in db.get_tablenames()) assert all(isinstance(x, str) for x in db.get_colnames()) assert db.is_registered(testdata['s1']) is True assert len(db.get_unique_directories()) == 1 assert db.select_duplicates() == [] assert db.select_duplicates(outname_base='S1A__IW___A_20150222T170750', scene='scene.zip') == [] assert len(db.select(mindate='20141001T192312', maxdate='20201001T192312')) == 1 assert len(db.select(polarizations=['VV'])) == 1 assert len(db.select(vectorobject=id.bbox())) == 1 assert len( db.select(sensor='S1A', vectorobject='foo', processdir=str(tmpdir), verbose=True)) == 1 assert len( db.select(sensor='S1A', mindate='foo', maxdate='bar', foobar='foobar')) == 1 out = db.select(vv=1, acquisition_mode=('IW', 'EW')) assert len(out) == 1 assert isinstance(out[0], str) db.add_tables(mytable) assert 'mytable' in db.get_tablenames() with pytest.raises(IOError): db.filter_scenelist([1]) db.close() with pyroSAR.Archive('test', postgres=True, port=5432, user=pguser, password=pgpassword) as db: assert db.size == (1, 0) shp = os.path.join(str(tmpdir), 'db.shp') db.export2shp(shp) db.drop_database() assert Vector(shp).nfeatures == 1 with pytest.raises(OSError): with pyroSAR.Archive('test', postgres=True, port=5432, user=pguser, password=pgpassword) as db: db.import_outdated(testdata['archive_old']) db.drop_database() with pytest.raises(SystemExit) as pytest_wrapped_e: pyroSAR.Archive('test', postgres=True, user='******', port=7080) assert pytest_wrapped_e.type == SystemExit
def test_archive2(tmpdir, testdata): dbfile = os.path.join(str(tmpdir), 'scenes.db') with pyroSAR.Archive(dbfile) as db: db.insert(testdata['s1'], verbose=False) assert db.size == (1, 0) shp = os.path.join(str(tmpdir), 'db.shp') db.export2shp(shp) os.remove(dbfile) assert not os.path.isfile(dbfile) assert Vector(shp).nfeatures == 1 with pytest.raises(OSError): with pyroSAR.Archive(dbfile) as db: db.import_outdated(testdata['archive_old'])
def test_archive(tmpdir, testdata): id = pyroSAR.identify(testdata['s1']) dbfile = os.path.join(str(tmpdir), 'scenes.db') db = pyroSAR.Archive(dbfile) db.insert(testdata['s1'], verbose=False) assert all(isinstance(x, str) for x in db.get_tablenames()) assert all(isinstance(x, str) for x in db.get_colnames()) assert db.is_registered(testdata['s1']) is True assert len(db.get_unique_directories()) == 1 assert db.select_duplicates() == [] assert db.select_duplicates(outname_base='S1A__IW___A_20150222T170750', scene='scene.zip') == [] assert len(db.select(mindate='20141001T192312', maxdate='20201001T192312')) == 1 assert len(db.select(polarizations=['VV'])) == 1 assert len(db.select(vectorobject=id.bbox())) == 1 assert len( db.select(sensor='S1A', vectorobject='foo', processdir=str(tmpdir), verbose=True)) == 1 assert len( db.select(sensor='S1A', mindate='foo', maxdate='bar', foobar='foobar')) == 1 out = db.select(vv=1, acquisition_mode=('IW', 'EW')) assert len(out) == 1 assert isinstance(out[0], str) db.insert(testdata['s1_3'], verbose=False) db.insert(testdata['s1_4'], verbose=False) db.drop_element(testdata['s1_3']) assert db.size == (2, 0) db.drop_element(testdata['s1_4']) db.add_tables(mytable) assert 'mytable' in db.get_tablenames() with pytest.raises(IOError): db.filter_scenelist([1]) db.close() with pyroSAR.Archive(dbfile) as db: assert db.size == (1, 0) shp = os.path.join(str(tmpdir), 'db.shp') db.export2shp(shp) pyroSAR.drop_archive(db) assert not os.path.isfile(dbfile) assert Vector(shp).nfeatures == 1 with pytest.raises(OSError): with pyroSAR.Archive(dbfile) as db: db.import_outdated(testdata['archive_old'])
def test_archive(): os.makedirs(tmpdir) id = pyroSAR.identify(testfile1) dbfile = os.path.join(tmpdir, 'scenes.db') db = pyroSAR.Archive(dbfile) db.insert(testfile1, verbose=False) assert db.is_registered(testfile1) is True assert len(db.get_unique_directories()) == 1 assert db.select_duplicates() == [] assert db.select_duplicates(outname_base='S1A__IW___A_20150222T170750', scene='scene.zip') == [] assert len(db.select(mindate='20141001T192312', maxdate='20201001T192312')) == 1 assert len(db.select(polarizations=['VV'])) == 1 assert len(db.select(vectorobject=id.bbox())) == 1 with pytest.raises(IOError): db.filter_scenelist([1]) db.close() # separately test the with statement with pyroSAR.Archive(dbfile) as db: assert db.size == (1, 0) shutil.rmtree(tmpdir)
def test_archive(tmpdir, testdata, appveyor): id = pyroSAR.identify(testdata['s1']) dbfile = os.path.join(str(tmpdir), 'scenes.db') if not appveyor: db = pyroSAR.Archive(dbfile) db.insert(testdata['s1'], verbose=False) assert db.is_registered(testdata['s1']) is True assert len(db.get_unique_directories()) == 1 assert db.select_duplicates() == [] assert db.select_duplicates(outname_base='S1A__IW___A_20150222T170750', scene='scene.zip') == [] assert len( db.select(mindate='20141001T192312', maxdate='20201001T192312')) == 1 assert len(db.select(polarizations=['VV'])) == 1 assert len(db.select(vectorobject=id.bbox())) == 1 assert len( db.select(sensor='S1A', vectorobject='foo', processdir=str(tmpdir), verbose=True)) == 1 assert len( db.select(sensor='S1A', mindate='foo', maxdate='bar', foobar='foobar')) == 1 assert len(db.select(vv=1, acquisition_mode=('IW', 'EW'))) == 1 with pytest.raises(IOError): db.filter_scenelist([1]) db.close() with pyroSAR.Archive(dbfile) as db: assert db.size == (1, 0) shp = os.path.join(str(tmpdir), 'db.shp') db.export2shp(shp) assert spatial.Vector(shp).nfeatures == 1 os.remove(dbfile) with pytest.raises(OSError): with pyroSAR.Archive(dbfile) as db: db.import_outdated(testdata['archive_old'])
def test_scene(): scene = 'pyroSAR/tests/data/S1A_IW_GRDH_1SDV_20150222T170750_20150222T170815_004739_005DD8_3768.zip' dbfile = os.path.join('pyroSAR/tests/data/', 'scenes.db') with pyroSAR.Archive(dbfile) as db: db.insert(scene, verbose=True) assert db.size == (1, 0) id = pyroSAR.identify(scene) test_dir = 'pyroSAR/tests/data/test' os.makedirs(test_dir) id.bbox(outname='pyroSAR/tests/data/test/bbox_test.shp') assert id.is_processed(test_dir) is False id.unpack('pyroSAR/tests/data/test') assert id.compression is None os.remove(dbfile) id.export2sqlite(dbfile) with pytest.raises(IOError): id.getGammaImages() assert id.getGammaImages(id.scene) == [] osvdir = os.path.join(id.scene, 'osv') if sys.version_info >= (2, 7, 9): id.getOSV(osvdir) with pyroSAR.OSV(osvdir) as osv: with pytest.raises(IOError): osv.catch(osvtype='XYZ') res = osv.catch(osvtype='RES', start=osv.mindate('POE'), stop=osv.maxdate('POE')) osv.retrieve(res) assert len(osv.getLocals('POE')) == 3 assert len(osv.getLocals('RES')) == 21 assert osv.match(id.start, 'POE') is not None assert osv.match(id.start, 'RES') is None osv.clean_res() else: with pytest.raises(RuntimeError): id.getOSV(osvdir, osvType='POE') shutil.rmtree(test_dir) os.remove(dbfile)