def test_fail_bad_endpoint_main_method(monkeypatch, tmpdir): argument_dict = { 'cos-endpoint': '127.0.0.1:9000', 'cos-bucket': 'test-bucket', 'cos-directory': 'test-directory', 'cos-dependencies-archive': 'test-archive.tgz', 'filepath': 'etc/tests/resources/test-notebookA.ipynb', 'inputs': 'test-file.txt', 'outputs': 'test-file/test-file-copy.txt', 'user-volume-path': None } monkeypatch.setattr(bootstrapper.OpUtil, "parse_arguments", lambda x: argument_dict) monkeypatch.setattr(bootstrapper.OpUtil, 'package_install', mock.Mock(return_value=True)) mocked_func = mock.Mock(return_value="default", side_effect=[ 'test-archive.tgz', 'test-file.txt', 'test-notebookA-output.ipynb', 'test-notebookA.html', 'test-file.txt' ]) monkeypatch.setattr(bootstrapper.FileOpBase, "get_object_storage_filename", mocked_func) monkeypatch.setenv("AWS_ACCESS_KEY_ID", "minioadmin") monkeypatch.setenv("AWS_SECRET_ACCESS_KEY", "minioadmin") with tmpdir.as_cwd(): with pytest.raises(minio.error.InvalidEndpointError): bootstrapper.main()
def test_fail_bad_notebook_main_method(monkeypatch, s3_setup, tmpdir): argument_dict = {'cos-endpoint': 'http://127.0.0.1:9000', 'cos-bucket': 'test-bucket', 'cos-directory': 'test-directory', 'cos-dependencies-archive': 'test-bad-archiveB.tgz', 'notebook': 'etc/tests/resources/test-bad-notebookB.ipynb', 'inputs': 'test-file.txt', 'outputs': 'test-file/test-copy-file.txt'} monkeypatch.setattr(bootstrapper, "parse_arguments", lambda x: argument_dict) monkeypatch.setattr(bootstrapper, "package_install", lambda: True) mocked_func = mock.Mock(return_value="default", side_effect=['test-bad-archiveB.tgz', 'test-file.txt', 'test-bad-notebookB-output.ipynb', 'test-bad-notebookB.html', 'test-file.txt']) monkeypatch.setattr(bootstrapper, "get_object_storage_filename", mocked_func) monkeypatch.setenv("AWS_ACCESS_KEY_ID", "minioadmin") monkeypatch.setenv("AWS_SECRET_ACCESS_KEY", "minioadmin") s3_setup.fput_object(bucket_name=argument_dict['cos-bucket'], object_name="test-file.txt", file_path="README.md") s3_setup.fput_object(bucket_name=argument_dict['cos-bucket'], object_name="test-bad-archiveB.tgz", file_path="etc/tests/resources/test-bad-archiveB.tgz") with tmpdir.as_cwd(): with pytest.raises(papermill.exceptions.PapermillExecutionError): bootstrapper.main()
def main_method_setup_execution(monkeypatch, s3_setup, tmpdir, argument_dict): """Primary body for main method testing...""" monkeypatch.setattr(bootstrapper.OpUtil, 'parse_arguments', lambda x: argument_dict) monkeypatch.setattr(bootstrapper.OpUtil, 'package_install', mock.Mock(return_value=True)) monkeypatch.setenv("AWS_ACCESS_KEY_ID", "minioadmin") monkeypatch.setenv("AWS_SECRET_ACCESS_KEY", "minioadmin") monkeypatch.setenv("TEST_ENV_VAR1", "test_env_var1") s3_setup.fput_object( bucket_name=argument_dict['cos-bucket'], object_name="test-directory/test-file.txt", file_path="etc/tests/resources/test-requirements-elyra.txt") s3_setup.fput_object( bucket_name=argument_dict['cos-bucket'], object_name="test-directory/test,file.txt", file_path="etc/tests/resources/test-bad-requirements-elyra.txt") s3_setup.fput_object(bucket_name=argument_dict['cos-bucket'], object_name="test-directory/test-archive.tgz", file_path="etc/tests/resources/test-archive.tgz") with tmpdir.as_cwd(): bootstrapper.main() test_file_list = [ 'test-archive.tgz', 'test-file.txt', 'test,file.txt', 'test-file/test-file-copy.txt', 'test-file/test,file/test,file-copy.txt', 'test-notebookA.ipynb', 'test-notebookA-output.ipynb', 'test-notebookA.html' ] # Ensure working directory has all the files. for file in test_file_list: assert os.path.isfile(file) # Ensure upload directory has all the files EXCEPT the output notebook # since it was it is uploaded as the input notebook (test-notebookA.ipynb) # (which is included in the archive at start). for file in test_file_list: if file != 'test-notebookA-output.ipynb': assert s3_setup.stat_object( bucket_name=argument_dict['cos-bucket'], object_name="test-directory/" + file) if file == "test-notebookA.html": with open("test-notebookA.html") as html_file: assert 'TEST_ENV_VAR1: test_env_var1' in html_file.read( )
def run_cmd(self, cmd): kwargs = {'encoding': 'utf-8'} if bootstrapper.IS_PY3 else {} tout = tempfile.TemporaryFile('w+', **kwargs) terr = tempfile.TemporaryFile('w+', **kwargs) sys.stdout, sys.stderr = tout, terr if cmd == 'bootstrap': bootstrapper.main('-e', self.venv, '-r', self.requirements) elif cmd.startswith('pip '): bootstrapper.pip_cmd(self.venv, cmd[4:].split(), echo=True) else: assert False, 'Command {0!r} is not supported!'.format(cmd) tout.seek(0) terr.seek(0) return (tout.read(), terr.read())
def test_fail_bad_notebook_main_method(monkeypatch, s3_setup, tmpdir): argument_dict = { 'cos-endpoint': 'http://' + MINIO_HOST_PORT, 'cos-bucket': 'test-bucket', 'cos-directory': 'test-directory', 'cos-dependencies-archive': 'test-bad-archiveB.tgz', 'filepath': 'etc/tests/resources/test-bad-notebookB.ipynb', 'inputs': 'test-file.txt', 'outputs': 'test-file/test-copy-file.txt', 'user-volume-path': None } monkeypatch.setattr(bootstrapper.OpUtil, "parse_arguments", lambda x: argument_dict) monkeypatch.setattr(bootstrapper.OpUtil, 'package_install', mock.Mock(return_value=True)) mocked_func = mock.Mock(return_value="default", side_effect=[ 'test-bad-archiveB.tgz', 'test-file.txt', 'test-bad-notebookB-output.ipynb', 'test-bad-notebookB.html', 'test-file.txt' ]) monkeypatch.setattr(bootstrapper.FileOpBase, "get_object_storage_filename", mocked_func) monkeypatch.setenv("AWS_ACCESS_KEY_ID", "minioadmin") monkeypatch.setenv("AWS_SECRET_ACCESS_KEY", "minioadmin") s3_setup.fput_object(bucket_name=argument_dict['cos-bucket'], object_name="test-file.txt", file_path="README.md") s3_setup.fput_object(bucket_name=argument_dict['cos-bucket'], object_name="test-bad-archiveB.tgz", file_path="etc/tests/resources/test-bad-archiveB.tgz") with tmpdir.as_cwd(): with pytest.raises(subprocess.CalledProcessError): bootstrapper.main()
def test_main_method(monkeypatch, s3_setup, tmpdir): argument_dict = { 'cos-endpoint': 'http://127.0.0.1:9000', 'cos-bucket': 'test-bucket', 'cos-directory': 'test-directory', 'cos-dependencies-archive': 'test-archive.tgz', 'notebook': 'etc/tests/resources/test-notebookA.ipynb', 'inputs': 'test-file.txt', 'outputs': 'test-file-copy.txt' } monkeypatch.setattr(bootstrapper, "parse_arguments", lambda x: argument_dict) monkeypatch.setattr(bootstrapper, "package_install", lambda: True) monkeypatch.setenv("AWS_ACCESS_KEY_ID", "minioadmin") monkeypatch.setenv("AWS_SECRET_ACCESS_KEY", "minioadmin") s3_setup.fput_object(bucket_name=argument_dict['cos-bucket'], object_name="test-directory/test-file.txt", file_path="README.md") s3_setup.fput_object(bucket_name=argument_dict['cos-bucket'], object_name="test-directory/test-archive.tgz", file_path="etc/tests/resources/test-archive.tgz") with tmpdir.as_cwd(): bootstrapper.main() post_run_local_file_list = [ 'test-archive.tgz', 'test-file.txt', 'test-file-copy.txt', 'test-notebookA-output.ipynb', 'test-notebookA.html' ] post_run_s3_file_list = [ 'test-archive.tgz', 'test-file.txt', 'test-file-copy.txt', 'test-notebookA.ipynb', 'test-notebookA.html' ] for file in post_run_local_file_list: assert os.path.isfile(file) for file in post_run_s3_file_list: assert s3_setup.stat_object( bucket_name=argument_dict['cos-bucket'], object_name="test-directory/" + file)