Skip to content

Commit a0082be

Browse files
committed
refactor: move encode logic from device to ImageUtils
1 parent 220266a commit a0082be

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

core/utils/device/device.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,7 @@ def get_text(self):
7171
actual_image_path = os.path.join(Settings.TEST_OUT_IMAGES, img_name)
7272
File.delete(actual_image_path)
7373
self.get_screen(path=actual_image_path, log_level=logging.DEBUG)
74-
text = ImageUtils.get_text(image_path=actual_image_path)
75-
if Settings.PYTHON_VERSION < 3:
76-
return text.decode('utf-8').strip()
77-
else:
78-
return text.encode('utf-8').strip().decode('utf-8')
74+
return ImageUtils.get_text(image_path=actual_image_path)
7975

8076
def wait_for_text(self, text, timeout=30, retry_delay=1):
8177
t_end = time.time() + timeout

core/utils/image_utils.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import pytesseract
1414
from PIL import Image
1515

16+
from core.settings import Settings
17+
1618

1719
class ImageUtils(object):
1820
@staticmethod
@@ -110,4 +112,7 @@ def get_text(image_path):
110112
row_text = pytesseract.image_to_string(image, lang='eng',
111113
config="-c tessedit_char_whitelist=%s_-." % char_whitelist).strip()
112114
text = "".join([s for s in row_text.splitlines(True) if s.strip()])
113-
return text.encode(encoding='utf-8', errors='ignore')
115+
if Settings.PYTHON_VERSION < 3:
116+
return str(text.decode('utf8').encode('utf8')).strip()
117+
else:
118+
return text.decode("utf-8").strip()

0 commit comments

Comments
 (0)