Ejemplo n.º 1
0
    def test_cpu_count_does_not_exist(self, mock_pool):
        def _side_effect():
            raise NotImplementedError

        old_method = multicore._get_context().cpu_count
        mock_cpu_count = mock.Mock()
        mock_cpu_count.side_effect = _side_effect
        multicore._get_context().cpu_count = mock_cpu_count

        augseq = iaa.Identity()
        with warnings.catch_warnings(record=True) as caught_warnings:
            warnings.simplefilter("always")
            with multicore.Pool(augseq, processes=-1):
                pass

        assert mock_cpu_count.call_count == 1
        assert mock_pool.call_count == 1
        # 'processes' arg to Pool was expected to be set to None as cpu_count
        # produced an error
        assert mock_pool.call_args_list[0][0][0] is None

        assert len(caught_warnings) == 1
        assert ("Could not find method multiprocessing.cpu_count(). "
                in str(caught_warnings[-1].message))

        multicore._get_context().cpu_count = old_method
Ejemplo n.º 2
0
 def test_mocked_no_nixos_python3(self, mock_version, mock_gctx,
                                  mock_system):
     with clean_context():
         mock_version.return_value = "Ubuntu"
         mock_system.return_value = "Linux"
         _ctx = multicore._get_context()
         assert mock_gctx.call_count == 1
         assert mock_gctx.call_args_list[0][0][0] is None
Ejemplo n.º 3
0
    def test_mocked_mac_and_37_cause_spawn(self, mock_version, mock_gctx,
                                           mock_system, mock_vi):
        with clean_context():

            def version_info(index):
                if isinstance(index, slice):
                    return 3, 7
                return 3 if index == 0 else 7

            mock_vi.__getitem__.side_effect = version_info

            mock_version.return_value = "foo"
            mock_system.return_value = "Darwin"
            _ctx = multicore._get_context()
            mock_gctx.assert_called_once_with("spawn")
Ejemplo n.º 4
0
 def test_mocked_no_nixos_python2(self, mock_version):
     with clean_context():
         mock_version.return_value = "Ubuntu"
         ctx = multicore._get_context()
         assert ctx is multiprocessing
Ejemplo n.º 5
0
 def test_mocked_nixos_python3(self, mock_gctx, mock_version):
     with clean_context():
         mock_version.return_value = "NixOS"
         _ctx = multicore._get_context()
         mock_gctx.assert_called_once_with("spawn")
Ejemplo n.º 6
0
 def test_mocked_nixos_python2(self, mock_version, mock_warn):
     with clean_context():
         mock_version.return_value = "NixOS"
         _ctx = multicore._get_context()
         assert mock_warn.call_count == 1