Skip to content

Commit

Permalink
Add unit test for the with_threading system through SCANCODEIO_PROCES…
Browse files Browse the repository at this point in the history
…SES setting #185

Signed-off-by: tdruez <tdruez@nexb.com>
  • Loading branch information
tdruez committed Jun 7, 2021
1 parent a7a112f commit be85c4b
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions scanpipe/tests/test_pipes.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,26 @@ def test_scanpipe_pipes_scancode_scan_package_and_save_results_timeout_error(sel
)
self.assertEqual(expected_message, error.message)

def test_scanpipe_pipes_scancode_scan_and_save_multiprocessing_with_threading(self):
def noop(*args, **kwargs):
pass

project1 = Project.objects.create(name="Analysis")
CodebaseResource.objects.create(project=project1, path="notice.NOTICE")

scan_func = mock.Mock(return_value=(None, None))
scan_func.__name__ = ""

with mock.patch("scanpipe.pipes.scancode.SCANCODEIO_PROCESSES", -1):
scancode._scan_and_save(project1, scan_func, noop)
with_threading = scan_func.call_args_list[-1].args[-1]
self.assertFalse(with_threading)

with mock.patch("scanpipe.pipes.scancode.SCANCODEIO_PROCESSES", 0):
scancode._scan_and_save(project1, scan_func, noop)
with_threading = scan_func.call_args_list[-1].args[-1]
self.assertTrue(with_threading)

def test_scanpipe_pipes_scancode_virtual_codebase(self):
project = Project.objects.create(name="asgiref")
input_location = self.data_location / "asgiref-3.3.0_scan.json"
Expand Down

0 comments on commit be85c4b

Please # to comment.