Skip to content

Commit

Permalink
FIX: formatting with black
Browse files Browse the repository at this point in the history
  • Loading branch information
ldevillez committed May 5, 2024
1 parent 3da8571 commit 3362033
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 28 deletions.
28 changes: 12 additions & 16 deletions svg2tikz/tikz_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

try:
SYS_OUTPUT_BUFFER = sys.stdout.buffer
except AttributeError: # pragma: no cover
except AttributeError: # pragma: no cover
logging.warning("Sys has no output buffer, redirecting to None")
SYS_OUTPUT_BUFFER = None

Expand Down Expand Up @@ -99,7 +99,7 @@ def escape_texchars(input_string):
return "".join([_tex_charmap.get(c, c) for c in input_string])


def copy_to_clipboard(text): # pragma: no cover
def copy_to_clipboard(text): # pragma: no cover
"""Copy text to the clipboard
Returns True if successful. False otherwise.
Expand Down Expand Up @@ -810,15 +810,14 @@ def style_to_tz(self, node=None):
# Special handling of switch as they are meta elements
if node.TAG == "switch":
pass
if style.get("display") == "none" :
if style.get("display") == "none":
return ["none"]
else:
if style.get("display") == "none" or not node.is_visible:
if node.TAG == "g":
return ["none"]
return []


options = []

# Stroke and fill
Expand Down Expand Up @@ -929,7 +928,6 @@ def trans_to_tz(self, node=None, is_node=False):
else:
options.append(f"xscale={x},yscale={y}")


elif "matrix" in str(trans):
tr = self.convert_unit_coord(Vector2d(trans.e, trans.f), False)
a = self.round_value(trans.a)
Expand Down Expand Up @@ -1136,7 +1134,6 @@ def convert_path_to_tikz(self, path):
current_pos.y = self.update_height(current_pos.y)
pos.y = self.update_height(pos.y)


start_ang_o, end_ang_o, r = calc_arc(
current_pos,
r,
Expand All @@ -1156,9 +1153,9 @@ def convert_path_to_tikz(self, path):
end_ang = self.round_value(end_ang_o % 360)
# # Does not to seem a problem anymore
# if start_ang_o < end_ang_o and not start_ang < end_ang:
# start_ang -= 360
# start_ang -= 360
# elif start_ang_o > end_ang_o and not start_ang > end_ang:
# end_ang -= 360
# end_ang -= 360

if not self.options.noreversey:
command.x_axis_rotation *= -1
Expand Down Expand Up @@ -1263,7 +1260,7 @@ def _handle_text(self, node):
shape = self.get_shape_inside(node)
if shape is None:
p = Vector2d(node.x, node.y)
else: #pragma: no cover
else: # pragma: no cover
# TODO Not working yet
p = Vector2d(shape.left, shape.bottom)

Expand Down Expand Up @@ -1440,7 +1437,7 @@ def effect(self):

def save_raw(self, _):
"""Save the file from the save as menu from inkscape"""
if self.options.clipboard: # pragma: no cover
if self.options.clipboard: # pragma: no cover
success = copy_to_clipboard(self.output_code.encode("utf8"))
if not success:
logging.error("Failed to put output on clipboard")
Expand All @@ -1463,7 +1460,7 @@ def run(self, args=None, output=SYS_OUTPUT_BUFFER):
"""
try:
# We parse it ourself in command line but letting it with inkscape
if not self.args_parsed:# pragma: no cover
if not self.args_parsed: # pragma: no cover
if args is None:
args = sys.argv[1:]

Expand All @@ -1479,7 +1476,7 @@ def run(self, args=None, output=SYS_OUTPUT_BUFFER):
self.options.output = output
self.load_raw()
self.save_raw(self.effect())
except inkex.utils.AbortExtension as err: # pragma: no cover
except inkex.utils.AbortExtension as err: # pragma: no cover
inkex.utils.errormsg(str(err))
sys.exit(inkex.utils.ABORT_STATUS)
finally:
Expand All @@ -1490,7 +1487,6 @@ def convert(self, svg_file=None, no_output=False, **kwargs):
self.options = self.arg_parser.parse_args()
self.args_parsed = True


if self.options.printversion:
print_version_info()
return ""
Expand Down Expand Up @@ -1553,7 +1549,7 @@ def convert_svg(svg_source, no_output=True, returnstring=True, **kwargs):
return effect.convert(io.StringIO(svg_source), no_output, **kwargs)


def main_inkscape(): # pragma: no cover
def main_inkscape(): # pragma: no cover
"""Inkscape interface"""
# Create effect instance and apply it.
effect = TikZPathExporter(inkscape_mode=True)
Expand All @@ -1565,11 +1561,11 @@ def print_version_info():
print(f"svg2tikz version {__version__}")


def main_cmdline(**kwargs): # pragma: no cover
def main_cmdline(**kwargs): # pragma: no cover
"""Main command line interface"""
effect = TikZPathExporter(inkscape_mode=False)
effect.convert(**kwargs)


if __name__ == "__main__": # pragma: no cover
if __name__ == "__main__": # pragma: no cover
main_inkscape()
23 changes: 17 additions & 6 deletions tests/test_complete_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from svg2tikz import convert_file


def create_test_from_filename(filename, utest, filename_output = None, **kwargs):
def create_test_from_filename(filename, utest, filename_output=None, **kwargs):
"""
Function to test the complete conversion with svg2tikz.
The svg should be located in tests/testsfiles/XXX.svg
Expand Down Expand Up @@ -41,6 +41,7 @@ def create_test_from_filename(filename, utest, filename_output = None, **kwargs)

class TestCompleteFiles(unittest.TestCase):
"""Class test for complete SVG"""

def test_crop(self):
"""Test convert with crop"""
filename = "crop"
Expand Down Expand Up @@ -75,7 +76,9 @@ def test_ellipse(self):
"""Test complete convert ellipse"""
filename = "ellipse"
create_test_from_filename(filename, self)
create_test_from_filename(filename, self, noreversey=True,filename_output="ellipse_noreversey")
create_test_from_filename(
filename, self, noreversey=True, filename_output="ellipse_noreversey"
)

def test_polylines_polygones(self):
"""Test complete convert polylines and polygones"""
Expand Down Expand Up @@ -106,7 +109,9 @@ def test_transforms(self):
"""Test complete convert transform"""
filename = "transform"
create_test_from_filename(filename, self)
create_test_from_filename(filename, self, filename_output="transform_noreversey", noreversey = True)
create_test_from_filename(
filename, self, filename_output="transform_noreversey", noreversey=True
)

def test_image(self):
"""Test complete convert image"""
Expand All @@ -122,13 +127,19 @@ def test_text(self):
"""Test complete convert text"""
filename = "text"
create_test_from_filename(filename, self)
create_test_from_filename(filename, self, filename_output="text_noreversey", noreversey = True)
create_test_from_filename(
filename, self, filename_output="text_noreversey", noreversey=True
)

def test_switch(self):
"""Test complete convert simple switch case"""
filename = "switch_simple"
create_test_from_filename(filename, self, filename_output="switch_simple_noverbose")
create_test_from_filename(filename, self, verbose=True, filename_output="switch_simple_verbose")
create_test_from_filename(
filename, self, filename_output="switch_simple_noverbose"
)
create_test_from_filename(
filename, self, verbose=True, filename_output="switch_simple_verbose"
)

def test_text_fill_color(self):
"""Test complete convert text with color case"""
Expand Down
5 changes: 2 additions & 3 deletions tests/test_geometrical_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_calc_arc(self):
ang = 0.0
fa = 0.0
fs = 0.0
pos = inkex.transforms.Vector2d(3.0,3.0)
pos = inkex.transforms.Vector2d(3.0, 3.0)
start_ang_o, end_ang_o, r_o = calc_arc(cp, r_i, ang, fa, fs, pos)
true_start_ang = 0
true_end_ang = 0
Expand All @@ -37,13 +37,12 @@ def test_calc_arc(self):
self.assertEqual(true_r.x, r_o.x)
self.assertEqual(true_r.y, r_o.y)


cp = inkex.transforms.Vector2d(3.0, 3.0)
r_i = inkex.transforms.Vector2d(1.0, 2.0)
ang = 0.0
fa = 0.0
fs = 0.0
pos = inkex.transforms.Vector2d(3.0,11.0)
pos = inkex.transforms.Vector2d(3.0, 11.0)
start_ang_o, end_ang_o, r_o = calc_arc(cp, r_i, ang, fa, fs, pos)
true_start_ang = -90
true_end_ang = -270
Expand Down
4 changes: 3 additions & 1 deletion tests/test_tikz_path_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,9 @@ def test_handle_shape(self):
def test_handle_text(self):
"""Testing handling ignoring text"""
tzpe = TikZPathExporter(inkscape_mode=False)
tzpe.convert(StringIO(SVG_TEXT), no_output=True, returnstring=True, ignore_text=True)
tzpe.convert(
StringIO(SVG_TEXT), no_output=True, returnstring=True, ignore_text=True
)
text_node = tzpe.svg.getElementById("textNode")

emtpy_str = tzpe._handle_text(text_node)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_utility_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from svg2tikz.tikz_export import (
escape_texchars,
copy_to_clipboard,
return_arg_parser_doc
return_arg_parser_doc,
)


Expand All @@ -40,7 +40,7 @@ def test_exscape_texchars(self):
for symbols in special_tex_chars:
self.assertEqual(symbols[1], escape_texchars(symbols[0]))

@unittest.skip("cannot run in GH action") # pragma: no cover
@unittest.skip("cannot run in GH action") # pragma: no cover
def test_copy_to_clipboard(self):
"""Test copy"""
self.assertTrue(copy_to_clipboard(b"Test text"))
Expand Down

0 comments on commit 3362033

Please sign in to comment.