Skip to content

Commit

Permalink
2 failing test fixes for Windows platform (#672)
Browse files Browse the repository at this point in the history
* 1 of 2 failing tests on Windows.

* 2 of 2 failing tests on Windows.
  • Loading branch information
surdouski committed Aug 12, 2022
1 parent d699e2a commit 77ba9c4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
23 changes: 14 additions & 9 deletions papermill/tests/test_exceptions.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import pickle
import tempfile

Expand All @@ -8,9 +9,11 @@

@pytest.fixture
def temp_file():
f = tempfile.NamedTemporaryFile()
yield f
f.close()
"""NamedTemporaryFile must be set in wb mode, closed without delete, opened with open(file, "rb"),
then manually deleted. Otherwise, file fails to be read due to permission error on Windows."""
with tempfile.NamedTemporaryFile(mode="wb", delete=False) as f:
yield f
os.unlink(f.name)


@pytest.mark.parametrize(
Expand All @@ -34,10 +37,12 @@ def temp_file():
def test_exceptions_are_unpickleable(temp_file, exc, args):
"""Ensure exceptions can be unpickled"""
err = exc(*args)
with open(temp_file.name, 'wb') as fd:
pickle.dump(err, fd)
pickle.dump(err, temp_file)
temp_file.close() # close to re-open for reading

# Read the Pickled File
temp_file.seek(0)
data = temp_file.read()
pickled_err = pickle.loads(data)
assert str(pickled_err) == str(err)
with open(temp_file.name, "rb") as read_file:
read_file.seek(0)
data = read_file.read()
pickled_err = pickle.loads(data)
assert str(pickled_err) == str(err)
10 changes: 5 additions & 5 deletions papermill/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import os
import pytest
import warnings

from unittest.mock import Mock, call
from tempfile import TemporaryDirectory
from pathlib import Path

from nbformat.v4 import new_notebook, new_code_cell

Expand Down Expand Up @@ -52,10 +52,10 @@ def test_retry():


def test_chdir():
old_cwd = os.getcwd()
old_cwd = Path.cwd()
with TemporaryDirectory() as temp_dir:
with chdir(temp_dir):
assert os.getcwd() != old_cwd
assert os.getcwd() == os.path.realpath(temp_dir)
assert Path.cwd() != old_cwd
assert Path.cwd() == Path(temp_dir)

assert os.getcwd() == old_cwd
assert Path.cwd() == old_cwd

0 comments on commit 77ba9c4

Please sign in to comment.