-
Notifications
You must be signed in to change notification settings - Fork 831
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test MML queries are valid in CI #4614
Merged
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
1 change: 1 addition & 0 deletions
1
scripts/empty_files/antarctica-icesheet-outlines-3857.zip.lastmod
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Thu 01 Jan 1970 12:00:00 AM UTC | ||
Binary file not shown.
1 change: 1 addition & 0 deletions
1
scripts/empty_files/antarctica-icesheet-polygons-3857.zip.lastmod
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Thu 01 Jan 1970 12:00:00 AM UTC |
Binary file not shown.
1 change: 1 addition & 0 deletions
1
scripts/empty_files/ne_110m_admin_0_boundary_lines_land.zip.lastmod
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Thu 01 Jan 1970 12:00:00 AM UTC |
Binary file not shown.
1 change: 1 addition & 0 deletions
1
scripts/empty_files/simplified-water-polygons-split-3857.zip.lastmod
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Thu 01 Jan 1970 12:00:00 AM UTC |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Thu 01 Jan 1970 12:00:00 AM UTC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#!/usr/bin/env python3 | ||
"""" | ||
Tests the queries in a CartoCSS MML file against a database. | ||
|
||
Ignore database settings in the MML file. | ||
""" | ||
import argparse | ||
import logging | ||
import psycopg2 | ||
import yaml | ||
|
||
EMPTY_POLYGON="""ST_SetSRID('POLYGON EMPTY'::geometry, 3857)""" | ||
|
||
class ResultHasRowsError(Exception): | ||
"""Class for layers that have """ | ||
pass | ||
|
||
def testLayer(layer, curs): | ||
datasource = layer["Datasource"] | ||
if datasource["type"] != "postgis": | ||
logging.warning("Layer type {} not supported".format(layer["type"])) | ||
return | ||
geometry_field=datasource["geometry_field"] | ||
|
||
full_query = """ | ||
SELECT "{}" FROM | ||
{} | ||
""".format(geometry_field, datasource["table"]) | ||
if "!bbox!" not in full_query: | ||
full_query += "\nWHERE {} && !bbox!".format(geometry_field) | ||
|
||
query = full_query.replace("!bbox!", EMPTY_POLYGON).replace("!pixel_width!", "0").replace("!pixel_height!", "0").replace("!scale_denominator!", "0") | ||
logging.debug("Running query {}".format(query)) | ||
curs.execute(query) | ||
if curs.rowcount != 0: | ||
raise ResultHasRowsError(query) | ||
|
||
def main(): | ||
# parse options | ||
parser = argparse.ArgumentParser( | ||
description="Test CartoCSS project queries against a database") | ||
|
||
|
||
parser.add_argument("-d", "--database", action="store", default="gis", | ||
help="Override database name to connect to") | ||
parser.add_argument("-H", "--host", action="store", | ||
help="Override database server host or socket directory") | ||
parser.add_argument("-p", "--port", action="store", | ||
help="Override database server port") | ||
parser.add_argument("-U", "--username", action="store", | ||
help="Override database user name") | ||
parser.add_argument("-v", "--verbose", action="store_true", | ||
help="Be more verbose. Overrides -q") | ||
parser.add_argument("-q", "--quiet", action="store_true", | ||
help="Only report serious problems") | ||
parser.add_argument("-w", "--password", action="store", | ||
help="Override database password") | ||
|
||
parser.add_argument('project', type=argparse.FileType('r'), | ||
help="CartoCSS MML file") | ||
opts = parser.parse_args() | ||
|
||
if opts.verbose: | ||
logging.basicConfig(level=logging.DEBUG) | ||
elif opts.quiet: | ||
logging.basicConfig(level=logging.WARNING) | ||
else: | ||
logging.basicConfig(level=logging.INFO) | ||
|
||
mml=yaml.safe_load(opts.project) | ||
logging.debug("Loaded MML") | ||
|
||
with psycopg2.connect(database=opts.database, host=opts.host, | ||
port=opts.port, user=opts.username, | ||
password=opts.password).cursor() as curs: | ||
curs.execute("SET default_transaction_read_only = TRUE;") | ||
for layer in mml["Layer"]: | ||
testLayer(layer, curs) | ||
|
||
|
||
|
||
|
||
if __name__ == '__main__': | ||
main() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This (and other) files has a different format than external_data.last_modified, causing an issue. TODO: Change these to
Thu, 01 Jan 1970 00:00:00 GMT
with no newline.