コード例 #1
0
def test_minimal():
    """The minimal amount of CSV data should be valid"""
    teardown()
    assert not TrackFile.instances
    assert not points
    
    csv = abspath(join('test', 'data', 'minimal.csv'))
    gui.open_files([csv])
    assert len(TrackFile.instances) == 1
    assert len(points) == 3
    assert len(CSVFile(csv).polygons) == 1
    
    for point in points.values():
        assert type(point.ele) is float
        assert point.ele == 0.0
    
    alpha = points[min(points)]
    omega = points[max(points)]
    
    assert alpha.lat == 49.885583
    assert alpha.lon == -97.151421
    assert alpha.ele == 0.0
    
    assert omega.lat == 49.885576
    assert omega.lon == -97.151397
    assert omega.ele == 0.0
コード例 #2
0
def test_timezone_lookups():
    """Ensure that the timezone can be discovered from the map"""
    # Be very careful to reset everything so that we're sure that
    # we're not just finding the timezone from gsettings.
    teardown()
    gst = GSettings('camera', 'canon_canon_powershot_a590_is')
    gst.reset('found-timezone')
    gst.reset('offset')
    gst.set_string('timezone-method', 'lookup')
    Camera.cache.clear()

    # Open just the GPX
    gui.open_files(GPXFILES)

    # At this point the camera hasn't been informed of the timezone
    assert gst.get_string('found-timezone') == ''

    # Opening a photo should place it on the map.
    gui.open_files([IMGFILES[0]])
    print(Camera.instances)
    print(gst.get_string('found-timezone'))
    assert gst.get_string('found-timezone') == 'America/Edmonton'
    assert Photograph.instances
    assert Camera.instances

    photo = list(Photograph.instances).pop()
    assert photo.latitude == 53.530476
    assert photo.longitude == -113.450635
コード例 #3
0
ファイル: test_csv.py プロジェクト: telkel/gottengeography
def test_minimal():
    """The minimal amount of CSV data should be valid"""
    teardown()
    assert not TrackFile.instances
    assert not points

    csv = abspath(join('test', 'data', 'minimal.csv'))
    gui.open_files([csv])
    assert len(TrackFile.instances) == 1
    assert len(points) == 3
    assert len(CSVFile(csv).polygons) == 1

    for point in points.values():
        assert type(point.ele) is float
        assert point.ele == 0.0

    alpha = points[min(points)]
    omega = points[max(points)]

    assert alpha.lat == 49.885583
    assert alpha.lon == -97.151421
    assert alpha.ele == 0.0

    assert omega.lat == 49.885576
    assert omega.lon == -97.151397
    assert omega.ele == 0.0
コード例 #4
0
def test_invalid_altitude():
    """Ensure that we can still read CSVs if the altitude data is corrupted"""
    teardown()
    assert not TrackFile.instances
    assert not points
    
    csv = abspath(join('test', 'data', 'missing_alt.csv'))
    gui.open_files([csv])
    assert len(TrackFile.instances) == 1
    assert len(points) == 10
    assert len(CSVFile(csv).polygons) == 1
    
    for point in points.values():
        assert type(point.ele) is float
        assert point.ele == 0.0
コード例 #5
0
ファイル: test_csv.py プロジェクト: telkel/gottengeography
def test_invalid_altitude():
    """Ensure that we can still read CSVs if the altitude data is corrupted"""
    teardown()
    assert not TrackFile.instances
    assert not points

    csv = abspath(join('test', 'data', 'missing_alt.csv'))
    gui.open_files([csv])
    assert len(TrackFile.instances) == 1
    assert len(points) == 10
    assert len(CSVFile(csv).polygons) == 1

    for point in points.values():
        assert type(point.ele) is float
        assert point.ele == 0.0
コード例 #6
0
ファイル: test_kml.py プロジェクト: telkel/gottengeography
def test_ordered():
    """Test that we can read a KML with ordered pairs"""
    teardown()
    assert not TrackFile.instances
    assert not points

    gui.open_files([KMLFILES[1]])
    assert len(TrackFile.instances) == 1
    assert len(points) == 84

    alpha = points[min(points)]
    omega = points[max(points)]

    assert alpha.lat == 39.6012887
    assert alpha.lon == 3.2617136
    assert alpha.ele == 185.0

    assert omega.lat == 39.6012402
    assert omega.lon == 3.2617779
    assert omega.ele == 0.0
コード例 #7
0
def test_ordered():
    """Test that we can read a KML with ordered pairs"""
    teardown()
    assert not TrackFile.instances
    assert not points

    gui.open_files([KMLFILES[1]])
    assert len(TrackFile.instances) == 1
    assert len(points) == 84

    alpha = points[min(points)]
    omega = points[max(points)]

    assert alpha.lat == 39.6012887
    assert alpha.lon == 3.2617136
    assert alpha.ele == 185.0

    assert omega.lat == 39.6012402
    assert omega.lon == 3.2617779
    assert omega.ele == 0.0
コード例 #8
0
ファイル: test_kml.py プロジェクト: telkel/gottengeography
def test_stupid_ordering():
    """Somebody at Google thought this was a good idea"""
    teardown()
    assert not TrackFile.instances
    assert not points

    gui.open_files([KMLFILES[0]])
    assert len(TrackFile.instances) == 1
    assert len(points) == 84

    alpha = points[min(points)]
    omega = points[max(points)]

    assert alpha.lat == 39.6012887
    assert alpha.lon == 3.2617136
    assert alpha.ele == 185.0

    assert omega.lat == 39.6012402
    assert omega.lon == 3.2617779
    assert omega.ele == 0.0

    gui.open_files([KMLFILES[1]])
    assert len(TrackFile.instances) == 2
    assert len(points) == 84

    one = KMLFile(KMLFILES[0]).tracks
    two = KMLFile(KMLFILES[1]).tracks

    # Both traces are identical, only the ordering in the XML differs
    for point in points:
        assert one[point].lat == two[point].lat
        assert one[point].lon == two[point].lon
        assert one[point].ele == two[point].ele

    # Test that points is valid even when destroying overlapping traces
    assert len(points) == 84
    KMLFile(KMLFILES[0]).destroy()
    assert len(points) == 84
    KMLFile(KMLFILES[1]).destroy()
    assert not points
コード例 #9
0
def test_stupid_ordering():
    """Somebody at Google thought this was a good idea"""
    teardown()
    assert not TrackFile.instances
    assert not points

    gui.open_files([KMLFILES[0]])
    assert len(TrackFile.instances) == 1
    assert len(points) == 84

    alpha = points[min(points)]
    omega = points[max(points)]

    assert alpha.lat == 39.6012887
    assert alpha.lon == 3.2617136
    assert alpha.ele == 185.0

    assert omega.lat == 39.6012402
    assert omega.lon == 3.2617779
    assert omega.ele == 0.0

    gui.open_files([KMLFILES[1]])
    assert len(TrackFile.instances) == 2
    assert len(points) == 84

    one = KMLFile(KMLFILES[0]).tracks
    two = KMLFile(KMLFILES[1]).tracks

    # Both traces are identical, only the ordering in the XML differs
    for point in points:
        assert one[point].lat == two[point].lat
        assert one[point].lon == two[point].lon
        assert one[point].ele == two[point].ele

    # Test that points is valid even when destroying overlapping traces
    assert len(points) == 84
    KMLFile(KMLFILES[0]).destroy()
    assert len(points) == 84
    KMLFile(KMLFILES[1]).destroy()
    assert not points
コード例 #10
0
def test_mytracks():
    """Test that we can read the output from Google's MyTracks app"""
    teardown()
    assert not TrackFile.instances
    assert not points
    
    csv = abspath(join('test', 'data', 'mytracks.csv'))
    gui.open_files([csv])
    assert len(TrackFile.instances) == 1
    assert len(points) == 100
    assert len(CSVFile(csv).polygons) == 2
    
    alpha = points[min(points)]
    omega = points[max(points)]
    
    assert alpha.lat == 49.887554
    assert alpha.lon == -97.131041
    assert alpha.ele == 217.1999969482422
    
    assert omega.lat == 49.885108
    assert omega.lon == -97.136677
    assert omega.ele == 195.6999969482422
コード例 #11
0
ファイル: test_csv.py プロジェクト: telkel/gottengeography
def test_mytracks():
    """Test that we can read the output from Google's MyTracks app"""
    teardown()
    assert not TrackFile.instances
    assert not points

    csv = abspath(join('test', 'data', 'mytracks.csv'))
    gui.open_files([csv])
    assert len(TrackFile.instances) == 1
    assert len(points) == 100
    assert len(CSVFile(csv).polygons) == 2

    alpha = points[min(points)]
    omega = points[max(points)]

    assert alpha.lat == 49.887554
    assert alpha.lon == -97.131041
    assert alpha.ele == 217.1999969482422

    assert omega.lat == 49.885108
    assert omega.lon == -97.136677
    assert omega.ele == 195.6999969482422
コード例 #12
0
def test_demo_data():
    """Load the demo data and ensure that we're reading it in properly"""
    teardown()
    assert not points
    assert not TrackFile.instances
    assert not TrackFile.range
    Widgets.photos_selection.emit('changed')
    # No buttons should be sensitive yet because nothing's loaded.
    buttons = {}
    for button in ('jump', 'save', 'revert', 'close'):
        buttons[button] = Widgets[button + '_button']
        assert not buttons[button].get_sensitive()

    # Load only the photos first.
    with ignored(OSError):
        TrackFile.load_from_file(IMGFILES[0])
        assert False  # Because it should have raised the exception
    gui.open_files(IMGFILES)

    # Nothing is yet selected or modified, so buttons still insensitive.
    for button in buttons.values():
        assert not button.get_sensitive()

    # Something loaded in the liststore?
    assert len(Widgets.loaded_photos) == 6
    assert Widgets.loaded_photos.get_iter_first()

    assert Photograph.instances
    for photo in Photograph.instances:
        assert not photo in modified
        assert not photo in selected

        # Pristine demo data shouldn't have any tags.
        assert not photo.altitude
        assert not photo.latitude
        assert not photo.longitude
        assert not photo.positioned

        # Add some crap
        photo.latitude = 10.0
        photo.altitude = 650
        photo.longitude = 45.0
        assert photo.positioned

        # photo.read() should discard all the crap we added above.
        # This is in response to a bug where I was using pyexiv2 wrongly
        # and it would load data from disk without discarding old data.
        photo.read()
        photo.lookup_geodata()
        assert not photo.geoname
        assert not photo.altitude
        assert not photo.latitude
        assert not photo.longitude
        assert not photo.positioned
        assert photo.filename == Label(photo).get_name()
        assert Label(photo).photo.filename == Label(photo).get_name()

    # Load the GPX
    with ignored(OSError):
        Photograph.load_from_file(GPXFILES[0])
        assert False  # Because it should have raised the exception
    gui.open_files(GPXFILES)

    # Check that the GPX is loaded
    assert len(points) == 374
    assert len(TrackFile.instances) == 1
    assert TrackFile.range[0] == 1287259751
    assert TrackFile.range[1] == 1287260756

    for photo in Photograph.instances:
        photo.update_derived_properties()

    Widgets.photos_selection.emit('changed')

    # The save button should be sensitive because loading GPX modifies
    # photos, but nothing is selected so the others are insensitive.
    assert buttons['save'].get_sensitive()
    for button in ('jump', 'revert', 'close'):
        assert not buttons[button].get_sensitive()

    assert Photograph.instances
    for photo in Photograph.instances:
        assert photo in modified

        assert photo.latitude
        assert photo.longitude
        assert photo.positioned
        assert Label(photo).get_property('visible')

    # Unload the GPX data.
    TrackFile.clear_all()
    assert not points
    assert not TrackFile.instances
    assert not TrackFile.range

    # Save all photos
    buttons['save'].emit('clicked')
    assert not modified
    for button in ('save', 'revert'):
        assert not buttons[button].get_sensitive()

    Widgets.photos_selection.select_all()
    assert len(selected) == 6
    for button in ('save', 'revert'):
        assert not buttons[button].get_sensitive()
    for button in ('jump', 'close'):
        assert buttons[button].get_sensitive()

    # Close all the photos.
    files = [photo.filename for photo in selected]
    buttons['close'].emit('clicked')
    for button in ('save', 'revert', 'close'):
        assert not buttons[button].get_sensitive()
    assert not Photograph.instances
    assert not modified
    assert not selected

    # Re-read the photos back from disk to make sure that the saving
    # was successful.
    assert len(files) == 6
    for filename in files:
        photo = Photograph(filename)
        photo.read()
        photo.update_derived_properties()
        print(photo.latitude, photo.longitude, photo.altitude)
        assert photo not in modified
        assert photo.positioned
        assert photo.latitude
        assert photo.longitude
        assert photo.altitude > 600
        assert photo.geoname == 'Edmonton, Alberta, Canada'
    assert not modified
    assert len(Photograph.instances) == 6
コード例 #13
0
def test_demo_data():
    """Load the demo data and ensure that we're reading it in properly"""
    teardown()
    assert not points
    assert not TrackFile.instances
    assert not TrackFile.range
    Widgets.photos_selection.emit("changed")
    # No buttons should be sensitive yet because nothing's loaded.
    buttons = {}
    for button in ("jump", "save", "revert", "close"):
        buttons[button] = Widgets[button + "_button"]
        assert not buttons[button].get_sensitive()

    # Load only the photos first.
    with ignored(OSError):
        TrackFile.load_from_file(IMGFILES[0])
        assert False  # Because it should have raised the exception
    gui.open_files(IMGFILES)

    # Nothing is yet selected or modified, so buttons still insensitive.
    for button in buttons.values():
        assert not button.get_sensitive()

    # Something loaded in the liststore?
    assert len(Widgets.loaded_photos) == 6
    assert Widgets.loaded_photos.get_iter_first()

    assert Photograph.instances
    for photo in Photograph.instances:
        assert not photo in modified
        assert not photo in selected

        # Pristine demo data shouldn't have any tags.
        assert not photo.altitude
        assert not photo.latitude
        assert not photo.longitude
        assert not photo.positioned

        # Add some crap
        photo.latitude = 10.0
        photo.altitude = 650
        photo.longitude = 45.0
        assert photo.positioned

        # photo.read() should discard all the crap we added above.
        # This is in response to a bug where I was using pyexiv2 wrongly
        # and it would load data from disk without discarding old data.
        photo.read()
        photo.lookup_geodata()
        assert not photo.geoname
        assert not photo.altitude
        assert not photo.latitude
        assert not photo.longitude
        assert not photo.positioned
        assert photo.filename == Label(photo).get_name()
        assert Label(photo).photo.filename == Label(photo).get_name()

    # Load the GPX
    with ignored(OSError):
        Photograph.load_from_file(GPXFILES[0])
        assert False  # Because it should have raised the exception
    gui.open_files(GPXFILES)

    # Check that the GPX is loaded
    assert len(points) == 374
    assert len(TrackFile.instances) == 1
    assert TrackFile.range[0] == 1287259751
    assert TrackFile.range[1] == 1287260756

    for photo in Photograph.instances:
        photo.update_derived_properties()

    Widgets.photos_selection.emit("changed")

    # The save button should be sensitive because loading GPX modifies
    # photos, but nothing is selected so the others are insensitive.
    assert buttons["save"].get_sensitive()
    for button in ("jump", "revert", "close"):
        assert not buttons[button].get_sensitive()

    assert Photograph.instances
    for photo in Photograph.instances:
        assert photo in modified

        assert photo.latitude
        assert photo.longitude
        assert photo.positioned
        assert Label(photo).get_property("visible")

    # Unload the GPX data.
    TrackFile.clear_all()
    assert not points
    assert not TrackFile.instances
    assert not TrackFile.range

    # Save all photos
    buttons["save"].emit("clicked")
    assert not modified
    for button in ("save", "revert"):
        assert not buttons[button].get_sensitive()

    Widgets.photos_selection.select_all()
    assert len(selected) == 6
    for button in ("save", "revert"):
        assert not buttons[button].get_sensitive()
    for button in ("jump", "close"):
        assert buttons[button].get_sensitive()

    # Close all the photos.
    files = [photo.filename for photo in selected]
    buttons["close"].emit("clicked")
    for button in ("save", "revert", "close"):
        assert not buttons[button].get_sensitive()
    assert not Photograph.instances
    assert not modified
    assert not selected

    # Re-read the photos back from disk to make sure that the saving
    # was successful.
    assert len(files) == 6
    for filename in files:
        photo = Photograph(filename)
        photo.read()
        photo.update_derived_properties()
        print(photo.latitude, photo.longitude, photo.altitude)
        assert photo not in modified
        assert photo.positioned
        assert photo.latitude
        assert photo.longitude
        assert photo.altitude > 600
        assert photo.geoname == "Edmonton, Alberta, Canada"
    assert not modified
    assert len(Photograph.instances) == 6