1
1
import os
2
2
import re
3
3
import shutil
4
- from subprocess import PIPE , CalledProcessError , run # nosec
4
+ from subprocess import PIPE , CalledProcessError , Popen , run
5
+ from sys import stderr # nosec
5
6
from unittest .mock import patch
6
7
7
8
import pytest
@@ -26,7 +27,7 @@ def rizin_in_system_path():
26
27
27
28
28
29
@pytest .fixture (scope = "module" )
29
- def rizin_version ():
30
+ def version_of_rizin_installed_on_system ():
30
31
rizin_in_system_path = shutil .which ("rizin" )
31
32
try :
32
33
process = run ( # nosec
@@ -164,9 +165,9 @@ def test_descriptor_to_androguard_format_with_combination():
164
165
165
166
166
167
def test_get_rizin_version_with_valid_path (
167
- rizin_in_system_path , rizin_version
168
+ rizin_in_system_path , version_of_rizin_installed_on_system
168
169
):
169
- expected_version = rizin_version
170
+ expected_version = version_of_rizin_installed_on_system
170
171
171
172
found_version = _get_rizin_version (rizin_in_system_path )
172
173
@@ -180,15 +181,15 @@ def test_get_rizin_version_with_invalid_path(tmp_path):
180
181
def test_download_rizin_successfully (tmp_path ):
181
182
target_path = tmp_path / "rizin"
182
183
183
- download_rizin ( target_path )
184
-
185
- assert os . access ( target_path , os . F_OK | os . X_OK )
184
+ with patch ( "quark.utils.tools._execute_command" ) as mock :
185
+ download_rizin ( target_path )
186
+ mock . assert_called_once ( )
186
187
187
188
188
189
def test_fail_to_download_rizin_due_to_unavailable_network (tmp_path ):
189
190
target_path = tmp_path / "rizin"
190
191
191
- with patch ("subprocess.Popen" ) as mock :
192
+ with patch ("subprocess.Popen.__new__ " ) as mock :
192
193
mock .side_effect = CalledProcessError (
193
194
"1" ,
194
195
"mock command" ,
@@ -202,7 +203,7 @@ def test_fail_to_download_rizin_due_to_unavailable_network(tmp_path):
202
203
def test_fail_to_download_rizin_due_to_unknown_errors (tmp_path ):
203
204
target_path = tmp_path / "rizin"
204
205
205
- with patch ("subprocess.Popen" ) as mock :
206
+ with patch ("subprocess.Popen.__new__ " ) as mock :
206
207
mock .side_effect = CalledProcessError ("1" , "mock command" , stderr = b"" )
207
208
208
209
assert not download_rizin (target_path )
@@ -254,13 +255,13 @@ def test_find_rizin_instance_installed_in_quark_directory():
254
255
target_commit = "Unused"
255
256
256
257
with patch ("shutil.which" ) as mocked_which :
257
- # Pretent there is no Rizin instance installed in the system.
258
+ # Pretend there is no Rizin instance installed in the system.
258
259
mocked_which .return_value = None
259
260
260
261
with patch (
261
262
"quark.utils.tools._get_rizin_version"
262
263
) as mocked_get_version :
263
- # Pretent the Rizin instance installed in the Quark directory is
264
+ # Pretend the Rizin instance installed in the Quark directory is
264
265
# compatible.
265
266
mocked_get_version .return_value = config .COMPATIBLE_RAZIN_VERSIONS [
266
267
0
@@ -286,20 +287,20 @@ def test_find_outdated_rizin_instance_installed_in_quark_directory(
286
287
target_commit = "Unused"
287
288
288
289
with patch ("shutil.which" ) as mocked_which :
289
- # Pretent there is no Rizin instance installed in the system.
290
+ # Pretend there is no Rizin instance installed in the system.
290
291
mocked_which .return_value = None
291
292
292
293
with patch (
293
294
"quark.utils.tools._get_rizin_version"
294
295
) as mocked_get_version :
295
- # Pretent the Rizin instance installed in the Quark directory is
296
+ # Pretend the Rizin instance installed in the Quark directory is
296
297
# not compatible.
297
298
mocked_get_version .return_value = "0.0.0"
298
299
299
300
with patch (
300
301
"quark.utils.tools.update_rizin"
301
302
) as mocked_update_rizin :
302
- # Pretent the upgrade is finished successfully.
303
+ # Pretend the upgrade is finished successfully.
303
304
mocked_update_rizin .return_value = True
304
305
305
306
# Must use the instance in the Quark directory.
@@ -342,13 +343,13 @@ def test_find_broken_rizin_instance_installed_in_quark_directory(
342
343
target_commit = "Unused"
343
344
344
345
with patch ("shutil.which" ) as mocked_which :
345
- # Pretent there is no Rizin instance installed in the system.
346
+ # Pretend there is no Rizin instance installed in the system.
346
347
mocked_which .return_value = "rizin_installed_in_system"
347
348
348
349
with patch (
349
350
"quark.utils.tools._get_rizin_version"
350
351
) as mocked_get_version :
351
- # Pretent -
352
+ # Pretend -
352
353
# 1. the Rizin instance in the system path is not compatible
353
354
# 2. the Rizin instance in the Quark directory is broken.
354
355
mocked_get_version .side_effect = (
@@ -360,15 +361,15 @@ def test_find_broken_rizin_instance_installed_in_quark_directory(
360
361
with patch (
361
362
"quark.utils.tools.download_rizin"
362
363
) as mocked_download_rizin :
363
- # Pretent we can download the source code successfully.
364
+ # Pretend we can download the source code successfully.
364
365
mocked_download_rizin .side_effect = (
365
366
_side_effort_for_downloading_rizin
366
367
)
367
368
368
369
with patch (
369
370
"quark.utils.tools.update_rizin"
370
371
) as mocked_update_rizin :
371
- # Pretent we can finish the upgrade successfully.
372
+ # Pretend we can finish the upgrade successfully.
372
373
mocked_update_rizin .return_value = True
373
374
374
375
result = find_rizin_instance (
@@ -406,13 +407,13 @@ def test_find_rizin_instance_failed_to_download_the_source():
406
407
target_commit = "Unused"
407
408
408
409
with patch ("shutil.which" ) as mocked_which :
409
- # Pretent there is no Rizin instance installed in the system.
410
+ # Pretend there is no Rizin instance installed in the system.
410
411
mocked_which .return_value = None
411
412
412
413
with patch (
413
414
"quark.utils.tools._get_rizin_version"
414
415
) as mocked_get_version :
415
- # Pretent the Rizin instance installed in the Quark directory is
416
+ # Pretend the Rizin instance installed in the Quark directory is
416
417
# broken.
417
418
mocked_get_version .return_value = None
418
419
@@ -442,20 +443,20 @@ def test_find_rizin_instance_failed_to_compile_or_update_the_source():
442
443
target_commit = "Unused"
443
444
444
445
with patch ("shutil.which" ) as mocked_which :
445
- # Pretent there is no Rizin instance installed in the system.
446
+ # Pretend there is no Rizin instance installed in the system.
446
447
mocked_which .return_value = None
447
448
448
449
with patch (
449
450
"quark.utils.tools._get_rizin_version"
450
451
) as mocked_get_version :
451
- # Pretent the Rizin instance installed in the Quark directory is
452
+ # Pretend the Rizin instance installed in the Quark directory is
452
453
# not compatible.
453
454
mocked_get_version .return_value = "0.0.0"
454
455
455
456
with patch (
456
457
"quark.utils.tools.update_rizin"
457
458
) as mocked_update_rizin :
458
- # Pretent the upgrade is finished successfully.
459
+ # Pretend the upgrade is finished successfully.
459
460
mocked_update_rizin .return_value = False
460
461
461
462
# Must use the instance in the Quark directory.
0 commit comments