|
8 | 8 | import csv |
9 | 9 | from unittest.mock import patch, MagicMock |
10 | 10 | from datetime import date, datetime |
| 11 | +from unittest import mock |
11 | 12 |
|
12 | 13 | def test_basic_imports(): |
13 | 14 | """Test para verificar que todas las librerías básicas se importan correctamente""" |
@@ -56,15 +57,18 @@ def resource_path(relative_path): |
56 | 57 | assert isinstance(result, str) |
57 | 58 | assert "test_file.txt" in result |
58 | 59 |
|
| 60 | +def resource_path(relative_path): |
| 61 | + try: |
| 62 | + base_path = sys._MEIPASS |
| 63 | + except AttributeError: |
| 64 | + base_path = os.path.abspath(".") |
| 65 | + return os.path.join(base_path, relative_path) |
| 66 | + |
59 | 67 | def test_resource_path_with_meipass(): |
60 | 68 | """Test para resource_path cuando existe _MEIPASS (PyInstaller)""" |
61 | | - def resource_path(relative_path): |
62 | | - try: |
63 | | - base_path = sys._MEIPASS |
64 | | - except AttributeError: |
65 | | - base_path = os.path.abspath(".") |
66 | | - return os.path.join(base_path, relative_path) |
67 | | - |
| 69 | + with mock.patch.object(sys, '_MEIPASS', '/tmp/fake_meipass', create=True): |
| 70 | + resultado = resource_path('archivo.txt') |
| 71 | + assert resultado == os.path.join('/tmp/fake_meipass', 'archivo.txt') |
68 | 72 | # Simulamos que _MEIPASS existe |
69 | 73 | with patch.object(sys, '_MEIPASS', '/tmp/pyinstaller'): |
70 | 74 | result = resource_path("icon.png") |
|
0 commit comments