def test_invalid_workspace(invalid_workspace):
    """
    Test that invalid workspaces raise ValidationError.

    Note that the parameterisation of this test, including that it raises a vaalidation
    error is controlled through `pytest_generate_tests`.
    """
    WorkspaceIO.parse_file(invalid_workspace)
def test_serialize_workspace(example, filename, monkeypatch):
    """Expect that ."""
    monkeypatch.syspath_prepend(EXAMPLES)
    example = import_module(example)
    path = DEFINITIONS / filename
    # TODO (midnighter): Use `from_orm` like `.construct` bypassing validation. (
    #  Requires a pull request on pydantic.)
    expected = WorkspaceIO.from_orm(Workspace.load(path))
    actual = WorkspaceIO.from_orm(example.main())
    assert json.loads(actual.json()) == json.loads(expected.json())
def test_save_and_load_workspace_to_string(monkeypatch):
    """Test saving as a JSON string and reloading."""
    monkeypatch.syspath_prepend(EXAMPLES)
    example = import_module("getting_started")
    workspace = example.main()

    json_string: str = workspace.dumps(indent=2)
    workspace2 = Workspace.loads(json_string)

    expected = WorkspaceIO.from_orm(workspace)
    actual = WorkspaceIO.from_orm(workspace2)
    assert json.loads(actual.json()) == json.loads(expected.json())
def test_save_and_load_workspace_to_gzipped_file(monkeypatch, tmp_path: Path):
    """Test saving as a zipped JSON file and reloading."""
    monkeypatch.syspath_prepend(EXAMPLES)
    example = import_module("getting_started")
    workspace = example.main()

    filepath = tmp_path / "test_workspace.json.gz"

    workspace.dump(filepath)
    workspace2 = Workspace.load(filepath)

    expected = WorkspaceIO.from_orm(workspace)
    actual = WorkspaceIO.from_orm(workspace2)
    assert json.loads(actual.json()) == json.loads(expected.json())
def test_invalid_workspace(invalid_workspace):
    WorkspaceIO.parse_file(invalid_workspace)