Skip to content
This repository was archived by the owner on May 17, 2019. It is now read-only.

Commit e48a0a0

Browse files
author
Marica Odagaki
committed
Fix test
1 parent ff997e3 commit e48a0a0

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

tests/test_native_package_install.py

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import json
22
import tarfile
33
import difflib
4+
import shutil
45

56
import native_package_install
67

78

8-
def test_main_does_not_download_twice(tmpdir, mocker):
9+
def test_main_does_not_download_twice_given_multiple_elm_packages(tmpdir, mocker):
910
native_elm_package = {'elm-lang/core': '1.0.0'}
1011
native_elm_package_path = tmpdir.join('elm-native-package.json')
1112
native_elm_package_path.write(json.dumps(native_elm_package))
@@ -35,24 +36,23 @@ def test_main_does_not_download_twice(tmpdir, mocker):
3536

3637
vendor = tmpdir.mkdir('vendor')
3738

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)
4141

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)
4646

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))
4951

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()
5454

55-
assert urlopen.call_count == 1
55+
assert mock_urlretrieve.call_count == 1
5656

5757

5858
def test_update_source_directories_makes_minimum_changes(tmpdir):

0 commit comments

Comments
 (0)