/
test.py
34 lines (27 loc) · 1.44 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# -*- coding: utf-8 -*-
from unittest import TestCase, mock
import pyrallelize, multiprocessing
class TestParallelDownload(TestCase):
def test_should_raise_a_exception_when_paramer_is_not_string_or_list(self):
self.assertRaises(TypeError, pyrallelize.pyrallelize, 1)
@mock.patch('pyrallelize._download')
def test_should_call_download_function_without_create_processes_when_parameter_is_a_string(self, *args):
pyrallelize.pyrallelize('http://www.google.com/')
self.assertEqual(pyrallelize._download.call_count, 1)
pyrallelize._download.assert_called_with('http://www.google.com/', '')
@mock.patch('pyrallelize._download')
@mock.patch('multiprocessing.pool.Pool')
def test_should_call_download_function_3_times(self, *args):
pyrallelize.pyrallelize([
'http://www.google.com/',
'http://www.github.com/',
'http://www.facebook.com/'
])
param = multiprocessing.pool.Pool.call_args_list[0][0][0]
self.assertEqual(multiprocessing.pool.Pool.call_count, 1)
self.assertEqual(param, 3)
@mock.patch('pyrallelize._download')
def test_should_receive_receive_correct_value_passed_on_directory_parameter(self, *args):
pyrallelize.pyrallelize('http://www.google.com/', 'dir_test/')
self.assertEqual(pyrallelize._download.call_count, 1)
pyrallelize._download.assert_called_with('http://www.google.com/', 'dir_test/')