Add command list.

This commit is contained in:
Sergey Vartanov 2021-09-27 23:55:30 +03:00
parent 9fc5c2069a
commit 4f1be1c60a
3 changed files with 26 additions and 15 deletions

View file

@ -11,7 +11,7 @@ from moire.moire import Tag
from map_machine import ui from map_machine import ui
from map_machine.icon import ShapeExtractor from map_machine.icon import ShapeExtractor
from map_machine.ui import COMMANDS from map_machine.ui import COMMAND_LINES
from map_machine.workspace import workspace from map_machine.workspace import workspace
__author__ = "Sergey Vartanov" __author__ = "Sergey Vartanov"
@ -143,7 +143,7 @@ class MapMachineMoire(Default, ABC):
def command(self, args: Arguments) -> str: def command(self, args: Arguments) -> str:
"""Bash command from integration tests.""" """Bash command from integration tests."""
return "map-machine " + " ".join(COMMANDS[self.clear(args[0])]) return "map-machine " + " ".join(COMMAND_LINES[self.clear(args[0])])
def icon(self, args: Arguments) -> str: def icon(self, args: Arguments) -> str:
"""Image with Röntgen icon.""" """Image with Röntgen icon."""

View file

@ -14,7 +14,7 @@ __email__ = "me@enzet.ru"
BOXES: str = " ▏▎▍▌▋▊▉" BOXES: str = " ▏▎▍▌▋▊▉"
BOXES_LENGTH: int = len(BOXES) BOXES_LENGTH: int = len(BOXES)
COMMANDS: dict[str, list[str]] = { COMMAND_LINES: dict[str, list[str]] = {
"render": ["render", "-b", "10.000,20.000,10.001,20.001"], "render": ["render", "-b", "10.000,20.000,10.001,20.001"],
"render_with_tooltips": [ "render_with_tooltips": [
"render", "render",
@ -27,6 +27,15 @@ COMMANDS: dict[str, list[str]] = {
"element": ["element", "--node", "amenity=bench,material=wood"], "element": ["element", "--node", "amenity=bench,material=wood"],
"tile": ["tile", "--coordinates", "50.000,40.000"], "tile": ["tile", "--coordinates", "50.000,40.000"],
} }
COMMANDS: list[str] = [
"render",
"server",
"tile",
"element",
"mapcss",
"icons",
"taginfo",
]
def parse_arguments(args: list[str]) -> argparse.Namespace: def parse_arguments(args: list[str]) -> argparse.Namespace:
@ -163,7 +172,7 @@ def add_tile_arguments(parser: argparse.ArgumentParser) -> None:
parser.add_argument( parser.add_argument(
"-b", "-b",
"--boundary-box", "--boundary-box",
help="construct the minimum amount of tiles that cover requested " help="construct the minimum amount of tiles that cover the requested "
"boundary box", "boundary box",
metavar="<lon1>,<lat1>,<lon2>,<lat2>", metavar="<lon1>,<lat1>,<lon2>,<lat2>",
) )
@ -181,7 +190,7 @@ def add_tile_arguments(parser: argparse.ArgumentParser) -> None:
"--input", "--input",
dest="input_file_name", dest="input_file_name",
metavar="<path>", metavar="<path>",
help="input OSM XML file name (if not specified, file will be " help="input OSM XML file name (if not specified, the file will be "
"downloaded using OpenStreetMap API)", "downloaded using OpenStreetMap API)",
) )
@ -233,8 +242,8 @@ def add_render_arguments(parser: argparse.ArgumentParser) -> None:
"-b", "-b",
"--boundary-box", "--boundary-box",
metavar="<lon1>,<lat1>,<lon2>,<lat2>", metavar="<lon1>,<lat1>,<lon2>,<lat2>",
help="geo boundary box; if first value is negative, enclose the value " help="geo boundary box; if the first value is negative, enclose the "
"with quotes and use space before `-`", "value with quotes and use space before `-`",
) )
parser.add_argument( parser.add_argument(
"--cache", "--cache",

View file

@ -10,7 +10,7 @@ __email__ = "me@enzet.ru"
from xml.etree import ElementTree from xml.etree import ElementTree
from xml.etree.ElementTree import Element from xml.etree.ElementTree import Element
from map_machine.ui import COMMANDS from map_machine.ui import COMMAND_LINES
def error_run(arguments: list[str], message: bytes) -> None: def error_run(arguments: list[str], message: bytes) -> None:
@ -41,7 +41,7 @@ def test_wrong_render_arguments() -> None:
def test_render() -> None: def test_render() -> None:
"""Test `render` command.""" """Test `render` command."""
run( run(
COMMANDS["render"] + ["--cache", "tests/data"], COMMAND_LINES["render"] + ["--cache", "tests/data"],
b"INFO Writing output SVG to out/map.svg...\n", b"INFO Writing output SVG to out/map.svg...\n",
) )
with Path("out/map.svg").open() as output_file: with Path("out/map.svg").open() as output_file:
@ -58,7 +58,7 @@ def test_render() -> None:
def test_render_with_tooltips() -> None: def test_render_with_tooltips() -> None:
"""Test `render` command.""" """Test `render` command."""
run( run(
COMMANDS["render_with_tooltips"] + ["--cache", "tests/data"], COMMAND_LINES["render_with_tooltips"] + ["--cache", "tests/data"],
b"INFO Writing output SVG to out/map.svg...\n", b"INFO Writing output SVG to out/map.svg...\n",
) )
with Path("out/map.svg").open() as output_file: with Path("out/map.svg").open() as output_file:
@ -76,7 +76,7 @@ def test_render_with_tooltips() -> None:
def test_icons() -> None: def test_icons() -> None:
"""Test `icons` command.""" """Test `icons` command."""
run( run(
COMMANDS["icons"], COMMAND_LINES["icons"],
b"INFO Icon grid is written to out/icon_grid.svg.\n" b"INFO Icon grid is written to out/icon_grid.svg.\n"
b"INFO Icons are written to out/icons_by_name and out/icons_by_id.\n", b"INFO Icons are written to out/icons_by_name and out/icons_by_id.\n",
) )
@ -91,7 +91,7 @@ def test_icons() -> None:
def test_mapcss() -> None: def test_mapcss() -> None:
"""Test `mapcss` command.""" """Test `mapcss` command."""
run( run(
COMMANDS["mapcss"], COMMAND_LINES["mapcss"],
b"INFO MapCSS 0.2 scheme is written to out/map_machine_mapcss.\n", b"INFO MapCSS 0.2 scheme is written to out/map_machine_mapcss.\n",
) )
@ -105,15 +105,17 @@ def test_mapcss() -> None:
def test_element() -> None: def test_element() -> None:
"""Test `element` command.""" """Test `element` command."""
run(COMMANDS["element"], b"INFO Element is written to out/element.svg.\n") run(
COMMAND_LINES["element"],
b"INFO Element is written to out/element.svg.\n",
)
assert (Path("out") / "element.svg").is_file() assert (Path("out") / "element.svg").is_file()
def test_tile() -> None: def test_tile() -> None:
"""Test `tile` command.""" """Test `tile` command."""
run( run(
COMMANDS["tile"] + ["--cache", "tests/data"], COMMAND_LINES["tile"] + ["--cache", "tests/data"],
b"INFO Tile is drawn to out/tiles/tile_18_160199_88904.svg.\n" b"INFO Tile is drawn to out/tiles/tile_18_160199_88904.svg.\n"
b"INFO SVG file is rasterized to out/tiles/tile_18_160199_88904.png.\n", b"INFO SVG file is rasterized to out/tiles/tile_18_160199_88904.png.\n",
) )