Skip to content

Commit

Permalink
TST: Adds tests for output_path of None
Browse files Browse the repository at this point in the history
  • Loading branch information
dcnadler committed Jun 27, 2022
1 parent e0b10a8 commit bb587e0
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
7 changes: 7 additions & 0 deletions papermill/tests/test_execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,13 @@ def test_report_mode(self):
self.assertEqual(cell.metadata.get('jupyter', {}).get('source_hidden'), True)


class TestOutputPathNone(unittest.TestCase):
def test_output_path_of_none(self):
"""Output path of None should return notebook node obj but not write an ipynb"""
nb = execute_notebook(get_notebook_path('simple_execute.ipynb'), None, {'msg': 'Hello'})
self.assertEqual(nb.metadata.papermill.parameters, {'msg': 'Hello'})


class TestCWD(unittest.TestCase):
def setUp(self):
self.test_dir = tempfile.mkdtemp()
Expand Down
24 changes: 24 additions & 0 deletions papermill/tests/test_iorw.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from ..iorw import (
HttpHandler,
LocalHandler,
NoIOHandler,
ADLHandler,
PapermillIO,
read_yaml_file,
Expand Down Expand Up @@ -90,6 +91,9 @@ def test_get_local_handler(self):
self.papermill_io.register("local", self.fake2)
self.assertEqual(self.papermill_io.get_handler("dne"), self.fake2)

def test_get_no_io_handler(self):
self.assertIsInstance(self.papermill_io.get_handler(None), NoIOHandler)

def test_entrypoint_register(self):

fake_entrypoint = Mock(load=Mock())
Expand Down Expand Up @@ -163,6 +167,9 @@ def test_write_with_no_file_extension(self):
with pytest.warns(UserWarning):
self.papermill_io.write("buffer", "fake/path")

def test_write_with_path_of_none(self):
self.assertIsNone(self.papermill_io.write('buffer', None))

def test_write_with_invalid_file_extension(self):
with pytest.warns(UserWarning):
self.papermill_io.write("buffer", "fake/path/fakeoutputpath.ipynb1")
Expand Down Expand Up @@ -246,6 +253,23 @@ def test_invalid_string(self):
LocalHandler().read("a random string")


class TestNoIOHandler(unittest.TestCase):
def test_raises_on_read(self):
with self.assertRaises(PapermillException):
NoIOHandler().read(None)

def test_raises_on_listdir(self):
with self.assertRaises(PapermillException):
NoIOHandler().listdir(None)

def test_write_returns_none(self):
self.assertIsNone(NoIOHandler().write('buf', None))

def test_pretty_path(self):
expect = 'Notebook will not be saved'
self.assertEqual(NoIOHandler().pretty_path(None), expect)


class TestADLHandler(unittest.TestCase):
"""
Tests for `ADLHandler`
Expand Down
4 changes: 4 additions & 0 deletions papermill/tests/test_parameterize.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,7 @@ def test_parameterized_path_with_none_parameters(self):
with self.assertRaises(PapermillMissingParameterException) as context:
parameterize_path("{foo}", None)
self.assertEqual(str(context.exception), "Missing parameter 'foo'")

def test_path_of_none_returns_none(self):
self.assertIsNone(parameterize_path(path=None, parameters={'foo': 'bar'}))
self.assertIsNone(parameterize_path(path=None, parameters=None))

0 comments on commit bb587e0

Please sign in to comment.