summaryrefslogtreecommitdiff
path: root/tests/unit/utils/test_utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit/utils/test_utils.py')
-rw-r--r--tests/unit/utils/test_utils.py43
1 files changed, 42 insertions, 1 deletions
diff --git a/tests/unit/utils/test_utils.py b/tests/unit/utils/test_utils.py
index 595aa6426..c833aa677 100644
--- a/tests/unit/utils/test_utils.py
+++ b/tests/unit/utils/test_utils.py
@@ -30,7 +30,7 @@ import shlex
import math
import operator
-from PyQt5.QtCore import QUrl, QRect
+from PyQt5.QtCore import QUrl, QRect, QPoint
from PyQt5.QtGui import QClipboard
import pytest
import hypothesis
@@ -1043,3 +1043,44 @@ class TestParseRect:
utils.parse_rect(s)
except ValueError as e:
print(e)
+
+
+class TestParsePoint:
+
+ @pytest.mark.parametrize('value, expected', [
+ ('1,1', QPoint(1, 1)),
+ ('123,789', QPoint(123, 789)),
+ ('-123,-789', QPoint(-123, -789)),
+ ])
+ def test_valid(self, value, expected):
+ assert utils.parse_point(value) == expected
+
+ @pytest.mark.parametrize('value, message', [
+ ('1x1', "String 1x1 does not match X,Y"),
+ ('1e0,1', "String 1e0,1 does not match X,Y"),
+ ('a,1', "String a,1 does not match X,Y"),
+ ('¹,1', "String ¹,1 does not match X,Y"),
+ ('1,,1', "String 1,,1 does not match X,Y"),
+ ('1', "String 1 does not match X,Y"),
+ ])
+ def test_invalid(self, value, message):
+ with pytest.raises(ValueError) as excinfo:
+ utils.parse_point(value)
+ assert str(excinfo.value) == message
+
+ @hypothesis.given(strategies.text())
+ def test_hypothesis_text(self, s):
+ try:
+ utils.parse_point(s)
+ except ValueError as e:
+ print(e)
+
+ @hypothesis.given(strategies.tuples(
+ strategies.integers(),
+ strategies.integers(),
+ ).map(lambda t: ",".join(map(str, t))))
+ def test_hypothesis_sophisticated(self, s):
+ try:
+ utils.parse_point(s)
+ except ValueError as e:
+ print(e)