|
1 | 1 | import json
|
2 | 2 | import tarfile
|
3 | 3 | import difflib
|
| 4 | +import shutil |
4 | 5 |
|
5 | 6 | import native_package_install
|
6 | 7 |
|
7 | 8 |
|
8 |
| -def test_main_does_not_download_twice(tmpdir, mocker): |
| 9 | +def test_main_does_not_download_twice_given_multiple_elm_packages(tmpdir, mocker): |
9 | 10 | native_elm_package = {'elm-lang/core': '1.0.0'}
|
10 | 11 | native_elm_package_path = tmpdir.join('elm-native-package.json')
|
11 | 12 | native_elm_package_path.write(json.dumps(native_elm_package))
|
@@ -35,24 +36,23 @@ def test_main_does_not_download_twice(tmpdir, mocker):
|
35 | 36 |
|
36 | 37 | vendor = tmpdir.mkdir('vendor')
|
37 | 38 |
|
38 |
| - urlopen = mocker.patch.object(native_package_install, 'urlopen') |
39 |
| - with open(str(fake_native_tarball_path)) as f: |
40 |
| - urlopen.return_value = f |
| 39 | + def write_tarfile(_, tar_filename): |
| 40 | + shutil.copyfile(str(fake_native_tarball_path), tar_filename) |
41 | 41 |
|
42 |
| - native_package_install.main( |
43 |
| - str(native_elm_package_path), |
44 |
| - list(map(str, (elm_package_one_path, elm_package_two_path))), |
45 |
| - str(vendor)) |
| 42 | + mock_urlretrieve = mocker.patch.object( |
| 43 | + native_package_install, |
| 44 | + 'urlretrieve', |
| 45 | + side_effect=write_tarfile) |
46 | 46 |
|
47 |
| - with open(str(fake_native_tarball_path)) as f: |
48 |
| - urlopen.return_value = f |
| 47 | + run_install = lambda: native_package_install.main( |
| 48 | + str(native_elm_package_path), |
| 49 | + list(map(str, (elm_package_one_path, elm_package_two_path))), |
| 50 | + str(vendor)) |
49 | 51 |
|
50 |
| - native_package_install.main( |
51 |
| - str(native_elm_package_path), |
52 |
| - list(map(str, (elm_package_one_path, elm_package_two_path))), |
53 |
| - str(vendor)) |
| 52 | + run_install() |
| 53 | + run_install() |
54 | 54 |
|
55 |
| - assert urlopen.call_count == 1 |
| 55 | + assert mock_urlretrieve.call_count == 1 |
56 | 56 |
|
57 | 57 |
|
58 | 58 | def test_update_source_directories_makes_minimum_changes(tmpdir):
|
|
0 commit comments