Commit 4c278cfc authored by Thomas Perret's avatar Thomas Perret

Support version parsing starting with string

parent 78ada346
......@@ -8,7 +8,7 @@ import six
def digits_only(string):
"""Return all digits that the given string starts with."""
match = re.match(r'(?P<digits>\d+)', string)
match = re.match(r'\D*(?P<digits>\d+)', string)
if match:
return int(match.group('digits'))
return 0
......
......@@ -97,6 +97,14 @@ class TestTesseract(BaseTest):
popen.return_value = self.stdout
self.assertSequenceEqual(tesseract.get_version(), (3, 0, 0))
@patch("subprocess.Popen")
def test_version_windows(self, popen):
message = self.message.replace("tesseract 4.0.0",
"tesseract v4.0.0.20181030")
self.stdout.stdout.read.return_value = message.encode()
popen.return_value = self.stdout
self.assertSequenceEqual(tesseract.get_version(), (4, 0, 0))
@patch("subprocess.Popen")
def test_version_error_splitting(self, popen):
message = self.message.replace("tesseract 4.0.0",
......
......@@ -71,7 +71,10 @@ class TestPyOCR(unittest.TestCase):
self.assertEqual(digits_only("azer"), 0)
self.assertEqual(digits_only("10.0.1"), 10)
self.assertEqual(digits_only("42azer"), 42)
self.assertEqual(digits_only("qsdf42azer"), 0)
self.assertEqual(digits_only("qsdf42azer"), 42)
self.assertEqual(digits_only("v42"), 42)
self.assertEqual(digits_only("v42x35"), 42)
self.assertEqual(digits_only("v42x35qsdf"), 42)
def test_is_on_path(self):
self.assertTrue(any((is_on_path("python"), is_on_path("python2"),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment