Skip to content

Commit

Permalink
test_pyi25.py : added new tests to improve coverage from 81% to 90%
Browse files Browse the repository at this point in the history
Signed-off-by: SONIABHISHEK121 <[email protected]>
  • Loading branch information
ABHISHEKSONI121 committed Jul 10, 2024
1 parent 48a17e6 commit 0d7ce70
Showing 1 changed file with 65 additions and 2 deletions.
67 changes: 65 additions & 2 deletions tests/test_pyi25.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
import os
import sys
import pytest
import win32com.server.register
import win32com.server.localserver


from pyafipws.pyi25 import PyI25, main
from PIL import Image, ImageChops
Expand All @@ -33,14 +36,15 @@

pyi25 = PyI25()


def test_GenerarImagen():
"Prueba de generación de imagen"
barras = "2026756539302400161203034739042201105299"
archivo = "prueba.png"
pyi25.GenerarImagen(barras, archivo)

assert os.path.exists(archivo)
#compare the image with a reference one
# compare the image with a reference one
ref = Image.open("tests/images/prueba-cae-i25.png")
test = Image.open(archivo)
diff = ImageChops.difference(ref, test)
Expand All @@ -67,21 +71,80 @@ def test_DigitoVerificadorModulo10():
barras = barras + pyi25.DigitoVerificadorModulo10(barras)
assert barras == "2026756539302400161203034739042201105299"


def test_main():
sys.argv = []
main()


def test_main_archivo():
sys.argv = []
sys.argv.append("--archivo")
sys.argv.append("test123.png")
main()


def test_main_mostrar(mocker):
mocker.patch("os.system")
sys.argv = []
sys.argv.append("--mostrar")
archivo = "prueba-cae-i25.png"
main()
if(sys.platform == 'linux2' or sys.platform == 'linux'):
if sys.platform == "linux2" or sys.platform == "linux":
os.system.assert_called_with("eog " "%s" "" % archivo)


def test_DigitoVerificadorModulo10_edge_cases():
assert pyi25.DigitoVerificadorModulo10("") == ""
assert pyi25.DigitoVerificadorModulo10("123") == "6"
assert pyi25.DigitoVerificadorModulo10("9999999999") == "0"


def test_main_custom_archivo():
sys.argv = ["pyi25.py", "--archivo", "custom_test.jpg"]
main()
assert os.path.exists("custom_test.jpg")
os.remove("custom_test.jpg")


@pytest.mark.parametrize("platform", ["win32", "darwin"])
def test_main_mostrar_non_linux(mocker, platform):
mocker.patch("sys.platform", platform)
mocker.patch("os.startfile")
sys.argv = ["pyi25.py", "--mostrar"]
main()
os.startfile.assert_called_once()


def test_GenerarImagen_odd_length_code():
barras = "12345"
archivo = "odd_test.png"
pyi25.GenerarImagen(barras, archivo)
assert os.path.exists(archivo)
with Image.open(archivo) as img:
assert img.size[0] > len(barras) * 3 # Check if 0 was prepended
os.remove(archivo)


def test_DigitoVerificadorModulo10_non_digit():
assert pyi25.DigitoVerificadorModulo10("12A34") == ""


def test_DigitoVerificadorModulo10_large_number():
large_number = "9" * 1000
result = pyi25.DigitoVerificadorModulo10(large_number)
assert len(result) == 1 and result.isdigit()


def test_main_with_register(mocker):
mocker.patch("win32com.server.register.UseCommandLine")
sys.argv = ["pyi25.py", "--register"]
main()
win32com.server.register.UseCommandLine.assert_called_once_with(PyI25)


def test_main_with_automate(mocker):
mocker.patch("win32com.server.localserver.serve")
sys.argv = ["pyi25.py", "/Automate"]
main()
win32com.server.localserver.serve.assert_called_once_with([PyI25._reg_clsid_])

0 comments on commit 0d7ce70

Please sign in to comment.