[Notes] [Git][BuildStream/buildstream][jonathan/workspace-fragment-multi-project] WIP: Extend tests to cover repeat opening and closing of workspaces



Title: GitLab

Jonathan Maw pushed to branch jonathan/workspace-fragment-multi-project at BuildStream / buildstream

Commits:

1 changed file:

Changes:

  • tests/frontend/workspace.py
    ... ... @@ -1213,13 +1213,89 @@ def test_external_list(cli, datafiles, tmpdir_factory):
    1213 1213
         result.assert_success()
    
    1214 1214
     
    
    1215 1215
     
    
    1216
    +@pytest.mark.datafiles(DATA_DIR)
    
    1217
    +def test_multiple_projects_no_force(cli, datafiles, tmpdir_factory):
    
    1218
    +    tmpdir1 = tmpdir_factory.mktemp('')
    
    1219
    +    tmpdir2 = tmpdir_factory.mktemp('')
    
    1220
    +    workspace_dir = os.path.join(str(tmpdir1), "workspace")
    
    1221
    +    alpha_project = os.path.join(str(tmpdir1), "alpha-project")
    
    1222
    +    beta_project = os.path.join(str(tmpdir2), "beta-project")
    
    1223
    +
    
    1224
    +    # Open the same workspace with two different projects
    
    1225
    +    # without force, we expect this to fail.
    
    1226
    +    alpha_element, alpha_project, _ = open_workspace(
    
    1227
    +        cli, tmpdir1, datafiles, "git", False, workspace_dir=workspace_dir,
    
    1228
    +        project_path=alpha_project, suffix="-alpha"
    
    1229
    +    )
    
    1230
    +
    
    1231
    +    message = "Opening an already-existing workspace without --force should fail"
    
    1232
    +    with pytest.raises(AssertionError, message=message):
    
    1233
    +        open_workspace(cli, tmpdir2, datafiles, "git", False, workspace_dir=workspace_dir,
    
    1234
    +                       project_path=beta_project, suffix="-beta", force=False)
    
    1235
    +
    
    1236
    +
    
    1237
    +@pytest.mark.datafiles(DATA_DIR)
    
    1238
    +def test_multiple_projects_repeat_open(cli, datafiles, tmpdir_factory):
    
    1239
    +    tmpdir1 = tmpdir_factory.mktemp('')
    
    1240
    +    tmpdir2 = tmpdir_factory.mktemp('')
    
    1241
    +    workspace_dir = os.path.join(str(tmpdir1), "workspace")
    
    1242
    +    other_workspace = os.path.join(str(tmpdir1), "workspace2")
    
    1243
    +    alpha_project = os.path.join(str(tmpdir1), "alpha-project")
    
    1244
    +    beta_project = os.path.join(str(tmpdir2), "beta-project")
    
    1245
    +
    
    1246
    +    # Open the same workspace with the same project twice to different workspaces
    
    1247
    +    # Expect this to succeed because we must use --force for multiple project
    
    1248
    +    # behaviour, anyway.
    
    1249
    +    # This test mostly exists so that this behaviour stays consistent.
    
    1250
    +    alpha_element, alpha_project, _ = open_workspace(
    
    1251
    +        cli, tmpdir1, datafiles, "git", False, workspace_dir=workspace_dir,
    
    1252
    +        project_path=alpha_project, suffix="-alpha"
    
    1253
    +    )
    
    1254
    +
    
    1255
    +    args = ['-C', workspace_dir, 'workspace', 'open', '-f', '--directory',
    
    1256
    +            other_workspace, alpha_element]
    
    1257
    +    result = cli.run(project=alpha_project, args=args)
    
    1258
    +    result.assert_success()
    
    1259
    +
    
    1260
    +
    
    1261
    +@pytest.mark.datafiles(DATA_DIR)
    
    1262
    +def test_multiple_projects_repeat_close(cli, datafiles, tmpdir_factory):
    
    1263
    +    tmpdir1 = tmpdir_factory.mktemp('')
    
    1264
    +    tmpdir2 = tmpdir_factory.mktemp('')
    
    1265
    +    workspace_dir = os.path.join(str(tmpdir1), "workspace")
    
    1266
    +    alpha_project = os.path.join(str(tmpdir1), "alpha-project")
    
    1267
    +    beta_project = os.path.join(str(tmpdir2), "beta-project")
    
    1268
    +
    
    1269
    +    alpha_element, alpha_project, _ = open_workspace(
    
    1270
    +        cli, tmpdir1, datafiles, "git", False, workspace_dir=workspace_dir,
    
    1271
    +        project_path=alpha_project, suffix="-alpha"
    
    1272
    +    )
    
    1273
    +
    
    1274
    +    beta_element, beta_project, _ = open_workspace(
    
    1275
    +        cli, tmpdir2, datafiles, "git", False, workspace_dir=workspace_dir,
    
    1276
    +        project_path=beta_project, suffix="-beta", force=True
    
    1277
    +    )
    
    1278
    +
    
    1279
    +    # Close the workspace from one project
    
    1280
    +    args = ["-C", workspace_dir, "workspace", "close"]
    
    1281
    +    result = cli.run(project=alpha_project, args=args)
    
    1282
    +    result.assert_success()
    
    1283
    +
    
    1284
    +    # Close the workspace from the other project
    
    1285
    +    result = cli.run(project=beta_project, args=args)
    
    1286
    +    result.assert_success()
    
    1287
    +
    
    1288
    +    # Close the project after it's been closed
    
    1289
    +    result = cli.run(project=beta_project, args=args)
    
    1290
    +    result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.MISSING_PROJECT_CONF)
    
    1291
    +
    
    1292
    +
    
    1216 1293
     @pytest.mark.datafiles(DATA_DIR)
    
    1217 1294
     @pytest.mark.parametrize(
    
    1218
    -    "force, close_from_external",
    
    1219
    -    [(False, False), (True, True), (True, False)],
    
    1220
    -    ids=["no-force", "close-from-external", "no-close-from-external"]
    
    1295
    +    "close_from_external", [(True), (False)],
    
    1296
    +    ids=["close-from-external", "no-close-from-external"]
    
    1221 1297
     )
    
    1222
    -def test_multiple_projects(cli, datafiles, tmpdir_factory, force, close_from_external):
    
    1298
    +def test_multiple_projects(cli, datafiles, tmpdir_factory, close_from_external):
    
    1223 1299
         # i.e. multiple projects can open the same workspace
    
    1224 1300
         tmpdir1 = tmpdir_factory.mktemp('')
    
    1225 1301
         tmpdir2 = tmpdir_factory.mktemp('')
    
    ... ... @@ -1232,18 +1308,11 @@ def test_multiple_projects(cli, datafiles, tmpdir_factory, force, close_from_ext
    1232 1308
             cli, tmpdir1, datafiles, "git", False, workspace_dir=workspace_dir,
    
    1233 1309
             project_path=alpha_project, suffix="-alpha"
    
    1234 1310
         )
    
    1235
    -    if force:
    
    1236
    -        beta_element, beta_project, _ = open_workspace(
    
    1237
    -            cli, tmpdir2, datafiles, "git", False, workspace_dir=workspace_dir,
    
    1238
    -            project_path=beta_project, suffix="-beta", force=force
    
    1239
    -        )
    
    1240
    -    else:
    
    1241
    -        # Opening a workspace on an existing workspace must only work with "--force"
    
    1242
    -        message = "Opening an already-existing workspace without --force should fail"
    
    1243
    -        with pytest.raises(AssertionError, message=message):
    
    1244
    -            open_workspace(cli, tmpdir2, datafiles, "git", False, workspace_dir=workspace_dir,
    
    1245
    -                           project_path=beta_project, suffix="-beta", force=force)
    
    1246
    -        return
    
    1311
    +
    
    1312
    +    beta_element, beta_project, _ = open_workspace(
    
    1313
    +        cli, tmpdir2, datafiles, "git", False, workspace_dir=workspace_dir,
    
    1314
    +        project_path=beta_project, suffix="-beta", force=True
    
    1315
    +    )
    
    1247 1316
     
    
    1248 1317
         # Run a command and assert it came from the alpha-element
    
    1249 1318
         # Using element guessing as a way of easily telling which project was used
    



  • [Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]