Speed up tests.

This commit is contained in:
Sergey Vartanov 2021-05-25 02:53:34 +03:00
parent f1702ece36
commit b7ed5353f8
4 changed files with 14 additions and 14 deletions

View file

@ -135,8 +135,8 @@ def draw_element(target: str, tags_description: str):
comma, key from value is separated by equals sign.
"""
tags = dict([x.split("=") for x in tags_description.split(",")])
scheme = Scheme(Path("scheme/default.yml"))
extractor = ShapeExtractor(
scheme: Scheme = Scheme(Path("scheme/default.yml"))
extractor: ShapeExtractor = ShapeExtractor(
Path("icons/icons.svg"), Path("icons/config.json")
)
icon, priority = scheme.get_icon(extractor, tags)
@ -166,7 +166,11 @@ def draw_grid() -> None:
Draw all possible icon shapes combinations as grid.
"""
os.makedirs("icon_set", exist_ok=True)
draw_all_icons("icon_grid.svg", "icon_set")
scheme: Scheme = Scheme(Path("scheme/default.yml"))
extractor: ShapeExtractor = ShapeExtractor(
Path("icons/icons.svg"), Path("icons/config.json")
)
draw_all_icons(scheme, extractor, "icon_grid.svg", "icon_set")
if __name__ == "__main__":

View file

@ -17,6 +17,7 @@ __email__ = "me@enzet.ru"
def draw_all_icons(
scheme: Scheme, extractor: ShapeExtractor,
output_file_name: str, output_directory: str, columns: int = 16,
step: float = 24, background_color: Color = Color("white"),
color: Color = Color("black")
@ -24,6 +25,8 @@ def draw_all_icons(
"""
Draw all possible icon combinations in grid.
:param scheme: tag specification
:param extractor: shape extractor for icon creation
:param output_file_name: output SVG file name for icon grid
:param output_directory: path to the directory to store individual SVG files
for icons
@ -32,15 +35,8 @@ def draw_all_icons(
:param background_color: background color
:param color: icon color
"""
scheme: Scheme = Scheme(Path("scheme/default.yml"))
icons: List[Icon] = []
icons_file_name: str = "icons/icons.svg"
extractor: ShapeExtractor = ShapeExtractor(
Path(icons_file_name), Path("icons/config.json")
)
def add() -> None:
"""
Construct icon and add it to the list.

View file

@ -4,7 +4,7 @@ from roentgen.icon import ShapeExtractor
from roentgen.scheme import Scheme
SCHEME: Scheme = Scheme(Path("scheme/default.yml"))
ICON_EXTRACTOR: ShapeExtractor = ShapeExtractor(
SCHEME_EXTRACTOR: ShapeExtractor = ShapeExtractor(
Path("icons/icons.svg"), Path("icons/config.json")
)

View file

@ -6,7 +6,7 @@ from typing import Dict
from roentgen.grid import draw_all_icons
from test import SCHEME, ICON_EXTRACTOR
from test import SCHEME, SCHEME_EXTRACTOR
__author__ = "Sergey Vartanov"
__email__ = "me@enzet.ru"
@ -15,11 +15,11 @@ __email__ = "me@enzet.ru"
def test_icons() -> None:
""" Test grid drawing. """
makedirs("icon_set", exist_ok=True)
draw_all_icons("temp.svg", "icon_set")
draw_all_icons(SCHEME, SCHEME_EXTRACTOR, "temp.svg", "icon_set")
def get_icon(tags: Dict[str, str]):
icon, _ = SCHEME.get_icon(ICON_EXTRACTOR, tags)
icon, _ = SCHEME.get_icon(SCHEME_EXTRACTOR, tags)
return icon