Example #1
0
def test_tile_coords(db_name):
    for zoom in range(1, 9):
        max = 2**zoom - 1
        stat1 = kahelo.kahelo('-count %s -quiet -records -zoom %d' %
                              (db_name, zoom))
        stat2 = kahelo.kahelo('-count %s -quiet -tiles 0,0,%d,%d  -zoom %d' %
                              (db_name, max, max, zoom))
        print(stat1, stat2)
        check('-tiles', stat1[1:-1] == stat2[1:-1])
Example #2
0
def test_contours():
    # test -contour versus -contours
    kahelo.kahelo('-describe test.db -db kahelo')
    stat1 = []
    stat2 = []
    for zoom in range(10, 17):
        stat1.append(
            kahelo.kahelo('-count test.db -zoom %d -contour  test2.gpx' %
                          zoom)[0])
        stat2.append(
            kahelo.kahelo('-count test.db -zoom %d -contours test2.gpx' %
                          zoom)[0])

    check('-contour', stat1 == [4, 10, 12, 22, 51, 128, 384])
    check('-contours', stat2 == [4, 10, 12, 20, 35, 82, 225])

    remove_db('test.db')
Example #3
0
def test_stat():
    temp = sys.stdout
    with open('test.txt', 'wt') as sys.stdout:
        try:
            kahelo.kahelo('-stat ./tests/easter.db -quiet -records')
            kahelo.kahelo(
                '-stat ./tests/easter.db -quiet -project test.project')
            kahelo.kahelo(
                '-stat ./tests/easter.db -quiet -track test.gpx -zoom 10-11')
            kahelo.kahelo(
                '-stat ./tests/easter.db -quiet -track test2.gpx -zoom 10-12')
        finally:
            sys.stdout = temp
    check('check stat', compare_texts('tests/test_stat.txt', 'test.txt'))
    os.remove('test.txt')
Example #4
0
def test_inside():
    """
    -inside limits de tile set to the tiles defined by the tile set in the 
    command line and already in the datebase.
    """
    temp = sys.stdout
    with open('test.txt', 'wt') as sys.stdout:
        try:
            # define tile coordinates of the test database
            kahelo.kahelo(
                '-count ./tests/easter.db -quiet -zoom 14 -tiles 3210,9471,3221,9479'
            )
            # one tile more on each side
            kahelo.kahelo(
                '-count ./tests/easter.db -quiet -zoom 14 -tiles 3209,9470,3222,9480'
            )
            # limiting to content, should be the same as first count
            kahelo.kahelo(
                '-count ./tests/easter.db -quiet -zoom 14 -tiles 3209,9470,3222,9480 -inside'
            )
        finally:
            sys.stdout = temp
    check('check inside', compare_texts('tests/test_inside.txt', 'test.txt'))
    os.remove('test.txt')
Example #5
0
def test_zoom_subdivision(url):
    kahelo.kahelo('-describe test.db -db kahelo -tile_ jpg -url %s' % url)
    kahelo.kahelo('-insert test.db -zoom 10-12 -track test.gpx')
    stat = kahelo.kahelo('-count test.db -zoom 10 -track test.gpx')
    check('subdiv1', stat == (4, 4, 0, 0))
    stat = kahelo.kahelo('-count test.db -zoom 11 -track test.gpx')
    check('subdiv2', stat == (9, 9, 0, 0))
    stat = kahelo.kahelo('-count test.db -zoom 12 -track test.gpx')
    check('subdiv3', stat == (11, 11, 0, 0))
    stat = kahelo.kahelo('-count test.db -zoom 11/10 -track test.gpx')
    check('subdiv4', stat == (16, 9, 0, 7))
    stat = kahelo.kahelo('-count test.db -zoom 12/10 -track test.gpx')
    check('subdiv5', stat == (64, 11, 0, 53))
    stat = kahelo.kahelo('-count test.db -zoom 12/11 -track test.gpx')
    check('subdiv6', stat == (36, 11, 0, 25))
    stat = kahelo.kahelo('-count test.db -zoom 12/12 -track test.gpx')
    check('subdiv7', stat == (11, 11, 0, 0))
    remove_db('test.db')
Example #6
0
def test_view():
    kahelo.resetconfig()
    kahelo.setconfig('view', 'draw_tracks', 'False')
    kahelo.setconfig('view', 'draw_tile_limits', 'False')
    kahelo.setconfig('view', 'draw_tile_width', 'False')
    kahelo.setconfig('view', 'draw_circles', 'False')
    kahelo.kahelo(
        '-view tests/easter.db -zoom 12 -project test.project -image test.png')
    check('check view 1',
          compare_files(os.path.join('tests', 'easter12a.png'), 'test.png'))
    kahelo.kahelo(
        '-view tests/easter.db -zoom 12 -project test.project -image test.jpg')
    check('check view 1',
          compare_files(os.path.join('tests', 'easter12a.jpg'), 'test.jpg'))

    kahelo.setconfig('view', 'draw_tracks', 'True')
    kahelo.kahelo(
        '-view tests/easter.db -zoom 12 -project test.project -image test.png')
    check('check view 1',
          compare_files(os.path.join('tests', 'easter12b.png'), 'test.png'))
    kahelo.kahelo(
        '-view tests/easter.db -zoom 12 -project test.project -image test.jpg')
    check('check view 1',
          compare_files(os.path.join('tests', 'easter12b.jpg'), 'test.jpg'))

    kahelo.setconfig('view', 'draw_tile_limits', 'True')
    kahelo.kahelo(
        '-view tests/easter.db -zoom 12 -project test.project -image test.png')
    check('check view 1',
          compare_files(os.path.join('tests', 'easter12c.png'), 'test.png'))
    kahelo.kahelo(
        '-view tests/easter.db -zoom 12 -project test.project -image test.jpg')
    check('check view 1',
          compare_files(os.path.join('tests', 'easter12c.jpg'), 'test.jpg'))

    kahelo.setconfig('view', 'draw_tile_width', 'True')
    kahelo.kahelo(
        '-view tests/easter.db -zoom 12 -project test.project -image test.png')
    check('check view 1',
          compare_files(os.path.join('tests', 'easter12d.png'), 'test.png'))
    kahelo.kahelo(
        '-view tests/easter.db -zoom 12 -project test.project -image test.jpg')
    check('check view 1',
          compare_files(os.path.join('tests', 'easter12d.jpg'), 'test.jpg'))

    kahelo.setconfig('view', 'draw_circles', 'True')
    kahelo.kahelo(
        '-view tests/easter.db -zoom 12 -project test.project -image test.png')
    check('check view 1',
          compare_files(os.path.join('tests', 'easter12e.png'), 'test.png'))
    kahelo.kahelo(
        '-view tests/easter.db -zoom 12 -project test.project -image test.jpg')
    check('check view 1',
          compare_files(os.path.join('tests', 'easter12e.jpg'), 'test.jpg'))

    os.remove('test.png')
    os.remove('test.jpg')
Example #7
0
def test_db(url,
            db_format,
            tile_format,
            db_dest_format,
            tile_dest_format,
            trace=''):
    # be sure context is clean
    clean()

    # describe test databases
    kahelo.kahelo('-describe test.db  -db %s -tile_f %s -url %s %s' %
                  (db_format, tile_format, url, trace))
    kahelo.kahelo('-describe test2.db -db %s -tile_f %s -url %s %s' %
                  (db_dest_format, tile_dest_format, url, trace))
    kahelo.kahelo('-describe test3.db -db %s -tile_f %s -url %s %s' %
                  (db_dest_format, tile_dest_format, url, trace))
    kahelo.kahelo('-describe test4.db -db %s -tile_f %s -url %s %s' %
                  (db_dest_format, tile_dest_format, url, trace))

    # check counting on empty databases
    stat = kahelo.kahelo('-count test.db -zoom 10-11 -track test.gpx %s' %
                         trace)
    check('test_db 1', stat == (13, 0, 0, 13))
    stat = kahelo.kahelo('-count test.db -zoom 12 -contour test.gpx %s' %
                         trace)
    check('test_db 2', stat == (12, 0, 0, 12))
    stat = kahelo.kahelo('-count test.db -project test.project %s' % trace)
    check('test_db 3', stat == (25, 0, 0, 25))

    # insert some track and contour
    kahelo.kahelo('-insert test.db -zoom 10-11 -track test.gpx %s' % trace)
    kahelo.kahelo('-insert test.db -zoom 12 -contour test.gpx %s' % trace)

    # check counting after insertion
    stat = kahelo.kahelo('-count test.db -project test.project %s' % trace)
    check('test_db 4', stat == (25, 25, 0, 0))
    stat = kahelo.kahelo('-count test.db -records %s' % trace)
    check('test_db 5', stat == (25, 25, 0, 0))
    stat = kahelo.kahelo('-count test.db -records -zoom 10,11,12 %s' % trace)
    check('test_db 6', stat == (25, 25, 0, 0))

    # export using various tile sets
    kahelo.kahelo(
        '-import test2.db -track test.gpx   -zoom 10-11 -source test.db %s' %
        trace)
    kahelo.kahelo(
        '-import test2.db -contour test.gpx -zoom 12    -source test.db %s' %
        trace)
    kahelo.kahelo(
        '-export test.db  -project test.project         -dest test3.db %s' %
        trace)
    kahelo.kahelo(
        '-export test.db  -records                      -dest test4.db %s' %
        trace)

    # check counts by using count_tiles and list_tiles methods
    db2 = kahelo.db_factory('test2.db')
    db3 = kahelo.db_factory('test3.db')
    db4 = kahelo.db_factory('test4.db')
    zooms = list(range(0, 21))
    check('7', db2.count_tiles(zooms) == db3.count_tiles(zooms))
    check('8', db2.count_tiles(zooms) == db4.count_tiles(zooms))
    check('9', set(db2.list_tiles(zooms)) == set(db3.list_tiles(zooms)))
    check('10', set(db2.list_tiles(zooms)) == set(db4.list_tiles(zooms)))
    db2.close()
    db3.close()
    db4.close()

    # delete all tiles
    kahelo.kahelo('-delete test2.db -zoom 10-11 -track test.gpx %s' % trace)
    kahelo.kahelo('-delete test2.db -zoom 12  -contour test.gpx %s' % trace)
    kahelo.kahelo('-delete test3.db -project test.project %s' % trace)
    kahelo.kahelo('-delete test4.db -records %s' % trace)

    # check counts by using count_tiles and list_tiles methods
    db2 = kahelo.db_factory('test2.db')
    db3 = kahelo.db_factory('test3.db')
    db4 = kahelo.db_factory('test4.db')
    zooms = range(0, 21)
    check('12', db2.count_tiles(zooms) == db3.count_tiles(zooms))
    check('13', db2.count_tiles(zooms) == db4.count_tiles(zooms))
    check('14', set(db2.list_tiles(zooms)) == set(db3.list_tiles(zooms)))
    check('15', set(db2.list_tiles(zooms)) == set(db4.list_tiles(zooms)))
    db2.close()
    db3.close()
    db4.close()

    clean()
Example #8
0
def main(verbose=False):
    if len(sys.argv) != 1:
        print(__doc__)
        exit(1)

    db_name = 'tests/easter.db'
    trace = '-verbose' if verbose else '-quiet'

    if os.name == 'nt':
        mode = 4
    else:
        mode = 3

    if mode == 1:
        # no window for subprocess, traces from server mixed with traces from client
        shell = False
        creationflags = 0
    elif mode == 2:
        # window for subprocess (windows only)
        shell = False
        creationflags = subprocess.CREATE_NEW_CONSOLE
    elif mode == 3:
        # no window for subprocess, traces from server mixed with traces from client
        shell = True
        creationflags = 0
    elif mode == 4:
        # no window for subprocess, no mixed traces (windows only)
        shell = True
        creationflags = subprocess.CREATE_NEW_CONSOLE

    kahelo.kahelo("-version")
    p = subprocess.Popen('kahelo -server tests/easter.db',
                         shell=shell,
                         creationflags=creationflags)
    # time.sleep(5)
    url = kahelo.server_url() + '/{zoom}/{x}/{y}.jpg'

    # make sure tests are done with known configuration
    config_filename = kahelo.configfilename()
    shutil.move(config_filename, config_filename + '.backup')
    kahelo.createconfig(config_filename, kahelo.DEFAULTS)

    try:
        define_tile_sets()

        for db1 in ('kahelo', 'rmaps', 'folder', 'maverick'):
            for db2 in ('kahelo', 'rmaps', 'folder', 'maverick'):
                print('--- TESTS with ---', db1, db2)
                test_db(url, db1, 'server', db2, 'png', trace=trace)  # jpg

        test_stat()
        # # TODO : test -inside

        # test_stat()
        test_view()
        test_contours()
        test_tile_coords(db_name)
        test_zoom_subdivision(url)
        test_inside()

        if test_result is True:
            print('All tests ok.')
        else:
            print('Failure...')

    finally:
        kahelo.stop_server()
        os.remove('test.gpx')
        os.remove('test2.gpx')
        os.remove('test.project')
        shutil.move(config_filename + '.backup', config_filename)