conftest.py 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #
  2. # Copyright 2018-2022 Elyra Authors
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. #
  16. import json
  17. import os
  18. import pytest
  19. from elyra.tests.contents.test_utils import create_dir
  20. from elyra.tests.contents.test_utils import create_file
  21. from elyra.tests.contents.test_utils import empty_notebook_content
  22. from elyra.tests.contents.test_utils import notebook_content
  23. from elyra.tests.contents.test_utils import python_content
  24. from elyra.tests.contents.test_utils import r_content
  25. from elyra.tests.contents.test_utils import text_content
  26. @pytest.fixture
  27. def directory_name():
  28. return "dir.py"
  29. @pytest.fixture
  30. def text_filename():
  31. return "test.txt"
  32. @pytest.fixture
  33. def notebook_filename():
  34. return "test.ipynb"
  35. @pytest.fixture
  36. def python_filename():
  37. return "test.py"
  38. @pytest.fixture
  39. def r_filename():
  40. return "test.r"
  41. @pytest.fixture
  42. def create_directory(jp_root_dir, directory_name):
  43. create_dir(jp_root_dir, directory_name)
  44. @pytest.fixture
  45. def create_text_file(jp_root_dir, text_filename):
  46. create_file(jp_root_dir, text_filename, text_content)
  47. @pytest.fixture(params=["", "@subdir"]) # Create in a "difficult" subdir https://github.com/elyra-ai/elyra/issues/2270
  48. def create_notebook_file(jp_root_dir, notebook_filename, request):
  49. create_file(jp_root_dir, notebook_filename, json.dumps(notebook_content), subdir=request.param)
  50. yield os.path.join(request.param, notebook_filename)
  51. @pytest.fixture(params=["", "@subdir"]) # Create in a "difficult" subdir https://github.com/elyra-ai/elyra/issues/2270
  52. def create_python_file(jp_root_dir, python_filename, request):
  53. create_file(jp_root_dir, python_filename, python_content, subdir=request.param)
  54. yield os.path.join(request.param, python_filename)
  55. @pytest.fixture(params=["", "@subdir"]) # Create in a "difficult" subdir https://github.com/elyra-ai/elyra/issues/2270
  56. def create_r_file(jp_root_dir, r_filename, request):
  57. create_file(jp_root_dir, r_filename, r_content, subdir=request.param)
  58. yield os.path.join(request.param, r_filename)
  59. @pytest.fixture(params=["", "@subdir"]) # Create in a "difficult" subdir https://github.com/elyra-ai/elyra/issues/2270
  60. def create_empty_notebook_file(jp_root_dir, notebook_filename, request):
  61. create_file(jp_root_dir, notebook_filename, json.dumps(empty_notebook_content), subdir=request.param)
  62. yield os.path.join(request.param, notebook_filename)
  63. # Set Elyra server extension as enabled (overriding server_config fixture from jupyter_server)
  64. @pytest.fixture
  65. def jp_server_config():
  66. return {"ServerApp": {"jpserver_extensions": {"elyra": True}}}