def test_workspace_yamls(): with load_workspace_from_yaml_paths( [ file_relative_path( __file__, "../../../docs_snippets/concepts/repositories_workspaces/workspace.yaml", ) ] ) as workspace: assert len(workspace.repository_location_handles) == 1 with load_workspace_from_yaml_paths( [ file_relative_path( __file__, "../../../docs_snippets/concepts/repositories_workspaces/workspace_working_directory.yaml", ) ] ) as workspace: assert len(workspace.repository_location_handles) == 1 with load_workspace_from_yaml_paths( [ file_relative_path( __file__, "../../../docs_snippets/concepts/repositories_workspaces/workspace_one_repository.yaml", ) ] ) as workspace: assert len(workspace.repository_location_handles) == 1 with load_workspace_from_yaml_paths( [ file_relative_path( __file__, "../../../docs_snippets/concepts/repositories_workspaces/workspace_python_package.yaml", ) ] ) as workspace: assert len(workspace.repository_location_handles) == 0 with load_workspace_from_yaml_paths( [ file_relative_path( __file__, "../../../docs_snippets/concepts/repositories_workspaces/workspace_grpc.yaml", ) ] ) as workspace: assert len(workspace.repository_location_handles) == 0
def test_bad_workspace_yaml_load(python_user_process_api): with TemporaryDirectory() as temp_dir: touch_file(os.path.join(temp_dir, "foo.yaml")) with pytest.raises( CheckError, match=( "Invariant failed. Description: Could not parse a workspace config from the " "yaml file at" ), ): load_workspace_from_yaml_paths( [os.path.join(temp_dir, "foo.yaml")], python_user_process_api )
def test_create_app_with_multiple_workspace_files(): with load_workspace_from_yaml_paths([ file_relative_path(__file__, "./workspace.yaml"), file_relative_path(__file__, "./override.yaml"), ], ) as workspace: assert create_app_from_workspace(workspace, DagsterInstance.ephemeral())
def test_multi_location_workspace(): workspace = load_workspace_from_yaml_paths( [file_relative_path(__file__, 'multi_location.yaml')]) assert isinstance(workspace, Workspace) assert len(workspace.repository_location_handles) == 2 assert workspace.has_repository_location_handle('loaded_from_file') assert workspace.has_repository_location_handle('loaded_from_module')
def test_load_in_process_location_handle_hello_world_terse(): workspace = load_workspace_from_yaml_paths( [file_relative_path(__file__, 'terse_python_file_workspace.yaml')] ) assert isinstance(workspace, Workspace) assert len(workspace.repository_location_handles) == 1 assert workspace.repository_location_handles[0].location_name == 'hello_world_repository'
def test_load_in_process_location_handle_hello_world_nested_with_def(): workspace = load_workspace_from_yaml_paths([ file_relative_path(__file__, 'nested_with_def_python_module_workspace.yaml') ]) assert isinstance(workspace, Workspace) assert len(workspace.repository_location_handles) == 1
def test_graphql_view_at_path_prefix(): workspace = load_workspace_from_yaml_paths( [file_relative_path(__file__, './workspace.yaml')]) with create_app_from_workspace(workspace, DagsterInstance.ephemeral(), '/dagster-path').test_client() as client: res = client.get('/dagster-path/graphql') assert b'Must provide query string' in res.data
def test_create_app_with_workspace(python_user_process_api): with load_workspace_from_yaml_paths( [file_relative_path(__file__, "./workspace.yaml")], python_user_process_api, ) as workspace: assert create_app_from_workspace(workspace, DagsterInstance.ephemeral())
def test_invalid_path_prefix(): with mock.patch('gevent.pywsgi.WSGIServer'), seven.TemporaryDirectory( ) as temp_dir: workspace = load_workspace_from_yaml_paths( [file_relative_path(__file__, './workspace.yaml')]) with pytest.raises(Exception) as exc_info: host_dagit_ui_with_workspace( storage_fallback=temp_dir, workspace=workspace, host=None, port=2343, port_lookup=False, path_prefix='no-leading-slash', ) assert 'path prefix should begin with a leading' in str(exc_info.value) with pytest.raises(Exception) as exc_info: host_dagit_ui_with_workspace( storage_fallback=temp_dir, workspace=workspace, host=None, port=2343, port_lookup=False, path_prefix='/extra-trailing-slash/', ) assert 'path prefix should not include a trailing' in str( exc_info.value)
def test_invalid_path_prefix(): with mock.patch("gevent.pywsgi.WSGIServer"), tempfile.TemporaryDirectory( ) as temp_dir: instance = DagsterInstance.local_temp(temp_dir) with load_workspace_from_yaml_paths( [file_relative_path(__file__, "./workspace.yaml")]) as workspace: with pytest.raises(Exception) as exc_info: host_dagit_ui_with_workspace( instance=instance, workspace=workspace, host=None, port=2343, port_lookup=False, path_prefix="no-leading-slash", ) assert "path prefix should begin with a leading" in str( exc_info.value) with pytest.raises(Exception) as exc_info: host_dagit_ui_with_workspace( instance=instance, workspace=workspace, host=None, port=2343, port_lookup=False, path_prefix="/extra-trailing-slash/", ) assert "path prefix should not include a trailing" in str( exc_info.value)
def test_load_in_process_location_hello_world_terse(): with load_workspace_from_yaml_paths( [file_relative_path(__file__, "terse_python_module_workspace.yaml")], ) as workspace: assert isinstance(workspace, Workspace) assert len(workspace.repository_locations) == 1 assert workspace.repository_locations[0].name == "dagster.utils.test.hello_world_repository"
def test_load_in_process_location_handle_hello_world_terse(): file_name = file_relative_path(__file__, "terse_python_file_workspace.yaml") with load_workspace_from_yaml_paths([file_name]) as workspace: assert isinstance(workspace, Workspace) assert len(workspace.repository_location_handles) == 1 assert workspace.repository_location_handles[0].location_name == "hello_world_repository.py"
def test_load_in_process_location_handle_hello_world_nested( python_user_process_api): with load_workspace_from_yaml_paths( [file_relative_path(__file__, "nested_python_module_workspace.yaml")], python_user_process_api, ) as workspace: assert isinstance(workspace, Workspace) assert len(workspace.repository_location_handles) == 1
def test_graphql_view_at_path_prefix(): with load_workspace_from_yaml_paths( [file_relative_path(__file__, "./workspace.yaml")]) as workspace: with create_app_from_workspace( workspace, DagsterInstance.ephemeral(), "/dagster-path").test_client() as client: res = client.get("/dagster-path/graphql") assert b"Must provide query string" in res.data
def test_load_in_process_location_hello_world_nested_with_def(): file_name = file_relative_path( __file__, "nested_with_def_python_file_workspace.yaml") with load_workspace_from_yaml_paths([file_name]) as workspace: assert isinstance(workspace, Workspace) assert len(workspace.repository_locations) == 1 assert (workspace.repository_locations[0].name == "hello_world_repository.py:hello_world_repository")
def test_multi_location_workspace(python_user_process_api): with load_workspace_from_yaml_paths( [file_relative_path(__file__, "multi_location.yaml")], python_user_process_api, ) as workspace: assert isinstance(workspace, Workspace) assert len(workspace.repository_location_handles) == 2 assert workspace.has_repository_location_handle("loaded_from_file") assert workspace.has_repository_location_handle("loaded_from_module")
def test_graphql_view(): workspace = load_workspace_from_yaml_paths( [file_relative_path(__file__, './workspace.yaml')], UserProcessApi.CLI) with create_app_from_workspace( workspace, DagsterInstance.ephemeral(), ).test_client() as client: res = client.get('/graphql') assert b'Must provide query string' in res.data
def test_create_app_with_multiple_workspace_files(python_user_process_api): workspace = load_workspace_from_yaml_paths( [ file_relative_path(__file__, './workspace.yaml'), file_relative_path(__file__, './override.yaml'), ], python_user_process_api, ) assert create_app_from_workspace(workspace, DagsterInstance.ephemeral())
def test_multi_location_workspace_foo(): with load_workspace_from_yaml_paths( [file_relative_path(__file__, "multi_location.yaml") ], ) as cli_workspace: assert isinstance(cli_workspace, Workspace) assert len(cli_workspace.repository_location_handles) == 3 assert cli_workspace.has_repository_location_handle("loaded_from_file") assert cli_workspace.has_repository_location_handle( "loaded_from_module") assert cli_workspace.has_repository_location_handle( "loaded_from_package") with load_workspace_from_yaml_paths( [file_relative_path(__file__, "multi_location.yaml") ], ) as grpc_workspace: assert isinstance(grpc_workspace, Workspace) assert len(grpc_workspace.repository_location_handles) == 3 assert grpc_workspace.has_repository_location_handle( "loaded_from_file") assert grpc_workspace.has_repository_location_handle( "loaded_from_module") assert grpc_workspace.has_repository_location_handle( "loaded_from_package") assert serialize_dagster_namedtuple( _get_single_code_pointer( cli_workspace, "loaded_from_file")) == serialize_dagster_namedtuple( _get_single_code_pointer(grpc_workspace, "loaded_from_file")) assert serialize_dagster_namedtuple( _get_single_code_pointer( cli_workspace, "loaded_from_module")) == serialize_dagster_namedtuple( _get_single_code_pointer(grpc_workspace, "loaded_from_module")) assert serialize_dagster_namedtuple( _get_single_code_pointer( cli_workspace, "loaded_from_package")) == serialize_dagster_namedtuple( _get_single_code_pointer(grpc_workspace, "loaded_from_package"))
def test_successful_host_dagit_ui_from_legacy_repository(): with mock.patch('gevent.pywsgi.WSGIServer'), seven.TemporaryDirectory( ) as temp_dir: workspace = load_workspace_from_yaml_paths( [file_relative_path(__file__, './workspace.yaml')]) host_dagit_ui_with_workspace(storage_fallback=temp_dir, workspace=workspace, host=None, port=2343, path_prefix='')
def test_load_in_process_location_handle_hello_world_nested_with_def(): with load_workspace_from_yaml_paths([ file_relative_path(__file__, "nested_with_def_python_module_workspace.yaml") ], ) as workspace: assert isinstance(workspace, Workspace) assert len(workspace.repository_location_handles) == 1 assert ( workspace.repository_location_handles[0].location_name == "dagster.utils.test.hello_world_repository:hello_world_repository")
def test_multi_file_extend_workspace(): with load_workspace_from_yaml_paths([ file_relative_path(__file__, "multi_location.yaml"), file_relative_path(__file__, "extra_location.yaml"), ], ) as workspace: assert isinstance(workspace, Workspace) assert len(workspace.repository_location_handles) == 4 assert workspace.has_repository_location_handle("loaded_from_file") assert workspace.has_repository_location_handle("loaded_from_module") assert workspace.has_repository_location_handle("loaded_from_package") assert workspace.has_repository_location_handle("extra_location")
def test_index_view(): workspace = load_workspace_from_yaml_paths( [file_relative_path(__file__, './workspace.yaml')], UserProcessApi.CLI) with create_app_from_workspace( workspace, DagsterInstance.ephemeral(), ).test_client() as client: res = client.get('/') assert res.status_code == 200, res.data assert b'You need to enable JavaScript to run this app' in res.data
def test_index_view(): with load_workspace_from_yaml_paths( [file_relative_path(__file__, "./workspace.yaml")]) as workspace: with create_app_from_workspace( workspace, DagsterInstance.ephemeral(), ).test_client() as client: res = client.get("/") assert res.status_code == 200, res.data assert b"You need to enable JavaScript to run this app" in res.data
def test_successful_host_dagit_ui_from_legacy_repository(): with mock.patch("gevent.pywsgi.WSGIServer"), tempfile.TemporaryDirectory( ) as temp_dir: instance = DagsterInstance.local_temp(temp_dir) with load_workspace_from_yaml_paths( [file_relative_path(__file__, "./workspace.yaml")]) as workspace: host_dagit_ui_with_workspace(instance=instance, workspace=workspace, host=None, port=2343, path_prefix="")
def test_load_legacy_repository_yaml(): with pytest.raises( DagsterInvariantViolationError, match=re.escape( "You are using the legacy repository yaml format. Please update your file " "to abide by the new workspace file format." ), ): with load_workspace_from_yaml_paths( [file_relative_path(__file__, "legacy_repository.yaml")], ): pass
def test_load_legacy_repository_yaml(): with pytest.warns( UserWarning, match=re.escape( "You are using the legacy repository yaml format. Please update your file " "to abide by the new workspace file format." ), ): with load_workspace_from_yaml_paths( [file_relative_path(__file__, "legacy_repository.yaml")], ) as workspace: assert isinstance(workspace, Workspace) assert len(workspace.repository_location_handles) == 1
def test_valid_path_prefix(): with mock.patch('gevent.pywsgi.WSGIServer'), seven.TemporaryDirectory( ) as temp_dir: workspace = load_workspace_from_yaml_paths( [file_relative_path(__file__, './workspace.yaml')]) host_dagit_ui_with_workspace( storage_fallback=temp_dir, workspace=workspace, host=None, port=2343, port_lookup=False, path_prefix='/dagster-path', )
def test_load_in_process_location_handle_hello_world_nested_with_def( python_user_process_api): workspace = load_workspace_from_yaml_paths( [ file_relative_path(__file__, 'nested_with_def_python_file_workspace.yaml') ], python_user_process_api, ) assert isinstance(workspace, Workspace) assert len(workspace.repository_location_handles) == 1 assert workspace.repository_location_handles[ 0].location_name == 'hello_world_repository'
def test_load_legacy_repository_yaml(python_user_process_api): with pytest.warns( UserWarning, match=re.escape( 'You are using the legacy repository yaml format. Please update your file ' 'to abide by the new workspace file format.'), ): workspace = load_workspace_from_yaml_paths( [file_relative_path(__file__, 'legacy_repository.yaml')], python_user_process_api, ) assert isinstance(workspace, Workspace) assert len(workspace.repository_location_handles) == 1