Skip to content

Commit

Permalink
Fix mock Python download
Browse files Browse the repository at this point in the history
  • Loading branch information
takluyver committed Oct 5, 2018
1 parent 109a04a commit 4f43b10
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
10 changes: 6 additions & 4 deletions nsist/tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@
import re
import responses
from shutil import copy
from testpath import MockCommand, assert_isfile, assert_isdir
from testpath import MockCommand, modified_env, assert_isfile, assert_isdir
from testpath.tempdir import TemporaryWorkingDirectory
from zipfile import ZipFile

from nsist import main
from nsist.util import CACHE_ENV_VAR
from .utils import test_dir

example_dir = Path(test_dir, 'console_example')

def respond_python_zip():
def respond_python_zip(req):
buf = io.BytesIO()
with ZipFile(buf, 'w') as zf:
zf.writestr('python.exe', b'')
return 200, {}, buf
return 200, {}, buf.getvalue()

@responses.activate
def test_console_example():
Expand All @@ -29,7 +30,8 @@ def test_console_example():
copy(str(src), td)


with MockCommand('makensis') as makensis:
with modified_env({CACHE_ENV_VAR: td}), \
MockCommand('makensis') as makensis:
ec = main(['installer.cfg'])

assert ec == 0
Expand Down
8 changes: 7 additions & 1 deletion nsist/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,14 @@ def download(url, target):
if chunk:
f.write(chunk)

CACHE_ENV_VAR = 'PYNSIST_CACHE_DIR'

def get_cache_dir(ensure_existence=False):
if os.name == 'posix' and sys.platform != 'darwin':
specified = os.environ.get(CACHE_ENV_VAR, None)

if specified:
p = Path(specified)
elif os.name == 'posix' and sys.platform != 'darwin':
# Linux, Unix, AIX, etc.
# use ~/.cache if empty OR not set
xdg = os.environ.get("XDG_CACHE_HOME", None) or (os.path.expanduser('~/.cache'))
Expand Down

0 comments on commit 4f43b10

Please sign in to comment.