Skip to content

Commit 39c1165

Browse files
committed
release 2023.0.1
1 parent a31a538 commit 39c1165

File tree

5 files changed

+24
-6
lines changed

5 files changed

+24
-6
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
All major and minor version changes will be documented in this file. Details of
44
patch-level version changes can be found in [commit messages](../../commits/master).
55

6+
## 2023.0.1 - 2023/03/12
7+
8+
- Raise `FileNotFoundError` when input does not exist
9+
610
## 2023 - 2023/01/08
711

812
- Add tox config

documentation/reference/svgtrace/index.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Svgtrace
1010

1111
## trace
1212

13-
[Show source in __init__.py:20](../../../svgtrace/__init__.py#L20)
13+
[Show source in __init__.py:17](../../../svgtrace/__init__.py#L17)
1414

1515
Do a trace of an image on the filesystem using the playwright library.
1616

@@ -26,6 +26,10 @@ for more information. Defaults to "default".
2626

2727
- `str` - SVG string
2828

29+
#### Raises
30+
31+
FileNotFoundError f"{filename} does not exist!"
32+
2933
#### Signature
3034

3135
```python

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "svgtrace"
3-
version = "2023"
3+
version = "2023.0.1"
44
license = "mit"
55
description = "Leverage playwright and the imagetrace.js library to trace a bitmap to svg in python"
66
authors = ["FredHappyface"]

svgtrace/__init__.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,9 @@
1111
from install_playwright import install
1212
from playwright.sync_api import sync_playwright
1313

14-
1514
THISDIR = str(Path(__file__).resolve().parent)
1615

1716

18-
19-
2017
def trace(filename: str, blackAndWhite: bool = False, mode: str = "default") -> str:
2118
"""Do a trace of an image on the filesystem using the playwright library.
2219
@@ -29,11 +26,17 @@ def trace(filename: str, blackAndWhite: bool = False, mode: str = "default") ->
2926
3027
Returns:
3128
str: SVG string
29+
30+
Raises:
31+
FileNotFoundError f"{filename} does not exist!"
3232
"""
3333
if mode.find("black") >= 0 or blackAndWhite:
3434
mode = "posterized1"
3535

36-
filename=filename.replace('\\', '/')
36+
filename = filename.replace("\\", "/")
37+
38+
if not Path(filename).exists():
39+
raise FileNotFoundError(f"{filename} does not exist!")
3740

3841
with sync_playwright() as p:
3942
install(p.chromium)

tests/test_main.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
from pathlib import Path
44

55
import imgcompare
6+
import pytest
67
from nocairosvg import svg2bitmap
78

89
THISDIR = str(Path(__file__).resolve().parent)
910
sys.path.insert(0, str(Path(THISDIR).parent))
1011
logoFile = f"{THISDIR}/data/logo"
12+
notExistsFile = f"{THISDIR}/data/notExists"
1113

1214
from svgtrace import trace
1315

@@ -28,3 +30,8 @@ def test_bw():
2830
def test_colour():
2931
Path(f"{logoFile}.svg").write_text(trace(f"{logoFile}.png"), encoding="utf-8")
3032
aux_comparesvg(f"{logoFile}.svg", "logo-actual.png")
33+
34+
35+
def test_notExists():
36+
with pytest.raises(FileNotFoundError):
37+
Path(f"{notExistsFile}.svg").write_text(trace(f"{notExistsFile}.png"), encoding="utf-8")

0 commit comments

Comments
 (0)