[Notes] [Git][BuildStream/buildstream][jonathan/workspace-fragment-guess-element] tests: Add tests for guessing element names



Title: GitLab

Jonathan Maw pushed to branch jonathan/workspace-fragment-guess-element at BuildStream / buildstream

Commits:

2 changed files:

Changes:

  • tests/frontend/workspace.py
    ... ... @@ -616,12 +616,15 @@ def test_list(cli, tmpdir, datafiles):
    616 616
     @pytest.mark.datafiles(DATA_DIR)
    
    617 617
     @pytest.mark.parametrize("kind", repo_kinds)
    
    618 618
     @pytest.mark.parametrize("strict", [("strict"), ("non-strict")])
    
    619
    -@pytest.mark.parametrize("call_from", [("project"), ("workspace")])
    
    620
    -def test_build(cli, tmpdir_factory, datafiles, kind, strict, call_from):
    
    619
    +@pytest.mark.parametrize("call_from,guess_element", [
    
    620
    +    ("project", "no-guess"), ("workspace", "guess"), ("workspace", "no-guess")
    
    621
    +])
    
    622
    +def test_build(cli, tmpdir_factory, datafiles, kind, strict, call_from, guess_element):
    
    621 623
         tmpdir = tmpdir_factory.mktemp('')
    
    622 624
         element_name, project, workspace = open_workspace(cli, tmpdir, datafiles, kind, False)
    
    623 625
         checkout = os.path.join(str(tmpdir), 'checkout')
    
    624
    -    args_pre = ['-C', workspace] if call_from == "workspace" else []
    
    626
    +    args_dir = ['-C', workspace] if call_from == "workspace" else []
    
    627
    +    args_elm = [element_name] if guess_element == "no-guess" else []
    
    625 628
     
    
    626 629
         # Modify workspace
    
    627 630
         shutil.rmtree(os.path.join(workspace, 'usr', 'bin'))
    
    ... ... @@ -644,14 +647,14 @@ def test_build(cli, tmpdir_factory, datafiles, kind, strict, call_from):
    644 647
         # Build modified workspace
    
    645 648
         assert cli.get_element_state(project, element_name) == 'buildable'
    
    646 649
         assert cli.get_element_key(project, element_name) == "{:?<64}".format('')
    
    647
    -    result = cli.run(project=project, args=args_pre + ['build', element_name])
    
    650
    +    result = cli.run(project=project, args=args_dir + ['build'] + args_elm)
    
    648 651
         result.assert_success()
    
    649 652
         assert cli.get_element_state(project, element_name) == 'cached'
    
    650 653
         assert cli.get_element_key(project, element_name) != "{:?<64}".format('')
    
    651 654
     
    
    652 655
         # Checkout the result
    
    653 656
         result = cli.run(project=project,
    
    654
    -                     args=args_pre + ['checkout', element_name, checkout])
    
    657
    +                     args=args_dir + ['checkout'] + args_elm + [checkout])
    
    655 658
         result.assert_success()
    
    656 659
     
    
    657 660
         # Check that the pony.conf from the modified workspace exists
    
    ... ... @@ -1061,24 +1064,31 @@ def test_multiple_failed_builds(cli, tmpdir, datafiles):
    1061 1064
     
    
    1062 1065
     
    
    1063 1066
     @pytest.mark.datafiles(DATA_DIR)
    
    1064
    -def test_external_fetch(cli, datafiles, tmpdir_factory):
    
    1067
    +@pytest.mark.parametrize("guess_element", [("guess"), ("no-guess")])
    
    1068
    +def test_external_fetch(cli, datafiles, tmpdir_factory, guess_element):
    
    1065 1069
         # Fetching from a workspace outside a project doesn't fail horribly
    
    1066 1070
         tmpdir = tmpdir_factory.mktemp('')
    
    1067 1071
         element_name, project, workspace = open_workspace(cli, tmpdir, datafiles, "git", False)
    
    1072
    +    arg_elm = [element_name] if guess_element == "no-guess" else []
    
    1068 1073
     
    
    1069
    -    result = cli.run(project=project, args=['-C', workspace, 'fetch', element_name])
    
    1074
    +    result = cli.run(project=project, args=['-C', workspace, 'fetch'] + arg_elm)
    
    1070 1075
         result.assert_success()
    
    1071 1076
     
    
    1072 1077
         # We already fetched it by opening the workspace, but we're also checking
    
    1073 1078
         # `bst show` works here
    
    1074
    -    assert cli.get_element_state(project, element_name) == 'buildable'
    
    1079
    +    result = cli.run(project=project,
    
    1080
    +                     args=['-C', workspace, 'show', '--deps', 'none', '--format', '%{state}'] + arg_elm)
    
    1081
    +    result.assert_success()
    
    1082
    +    assert result.output.strip() == 'buildable'
    
    1075 1083
     
    
    1076 1084
     
    
    1077 1085
     @pytest.mark.datafiles(DATA_DIR)
    
    1078
    -def test_external_push_pull(cli, datafiles, tmpdir_factory):
    
    1086
    +@pytest.mark.parametrize("guess_element", [("guess"), ("no-guess")])
    
    1087
    +def test_external_push_pull(cli, datafiles, tmpdir_factory, guess_element):
    
    1079 1088
         # Pushing and pulling to/from an artifact cache works from an external workspace
    
    1080 1089
         tmpdir = tmpdir_factory.mktemp('')
    
    1081 1090
         element_name, project, workspace = open_workspace(cli, tmpdir, datafiles, "git", False)
    
    1091
    +    args_elm = [element_name] if guess_element == "no-guess" else []
    
    1082 1092
     
    
    1083 1093
         with create_artifact_share(os.path.join(str(tmpdir), 'artifactshare')) as share:
    
    1084 1094
             result = cli.run(project=project, args=['-C', workspace, 'build', element_name])
    
    ... ... @@ -1088,22 +1098,24 @@ def test_external_push_pull(cli, datafiles, tmpdir_factory):
    1088 1098
                 'artifacts': {'url': share.repo, 'push': True}
    
    1089 1099
             })
    
    1090 1100
     
    
    1091
    -        result = cli.run(project=project, args=['-C', workspace, 'push', element_name])
    
    1101
    +        result = cli.run(project=project, args=['-C', workspace, 'push'] + args_elm)
    
    1092 1102
             result.assert_success()
    
    1093 1103
     
    
    1094
    -        result = cli.run(project=project, args=['-C', workspace, 'pull', '--deps', 'all', element_name])
    
    1104
    +        result = cli.run(project=project, args=['-C', workspace, 'pull', '--deps', 'all'] + args_elm)
    
    1095 1105
             result.assert_success()
    
    1096 1106
     
    
    1097 1107
     
    
    1098 1108
     @pytest.mark.datafiles(DATA_DIR)
    
    1099
    -def test_external_track(cli, datafiles, tmpdir_factory):
    
    1109
    +@pytest.mark.parametrize("guess_element", [("guess"), ("no-guess")])
    
    1110
    +def test_external_track(cli, datafiles, tmpdir_factory, guess_element):
    
    1100 1111
         # Tracking does not get horribly confused
    
    1101 1112
         tmpdir = tmpdir_factory.mktemp('')
    
    1102 1113
         element_name, project, workspace = open_workspace(cli, tmpdir, datafiles, "git", True)
    
    1114
    +    args_elm = [element_name] if guess_element == "no-guess" else []
    
    1103 1115
     
    
    1104 1116
         # The workspace is necessarily already tracked, so we only care that
    
    1105 1117
         # there's no weird errors.
    
    1106
    -    result = cli.run(project=project, args=['-C', workspace, 'track', element_name])
    
    1118
    +    result = cli.run(project=project, args=['-C', workspace, 'track'] + args_elm)
    
    1107 1119
         result.assert_success()
    
    1108 1120
     
    
    1109 1121
     
    
    ... ... @@ -1141,15 +1153,17 @@ def test_external_close_other(cli, datafiles, tmpdir_factory):
    1141 1153
     
    
    1142 1154
     
    
    1143 1155
     @pytest.mark.datafiles(DATA_DIR)
    
    1144
    -def test_external_close_self(cli, datafiles, tmpdir_factory):
    
    1156
    +@pytest.mark.parametrize("guess_element", [("guess"), ("no-guess")])
    
    1157
    +def test_external_close_self(cli, datafiles, tmpdir_factory, guess_element):
    
    1145 1158
         # >From inside an external workspace, close it
    
    1146 1159
         tmpdir1 = tmpdir_factory.mktemp('')
    
    1147 1160
         tmpdir2 = tmpdir_factory.mktemp('')
    
    1148 1161
         # Making use of the assumption that it's the same project in both invocations of open_workspace
    
    1149 1162
         alpha_element, project, alpha_workspace = open_workspace(cli, tmpdir1, datafiles, "git", False, suffix="-alpha")
    
    1150 1163
         beta_element, _, beta_workspace = open_workspace(cli, tmpdir2, datafiles, "git", False, suffix="-beta")
    
    1164
    +    arg_elm = [alpha_element] if guess_element == "no-guess" else []
    
    1151 1165
     
    
    1152
    -    result = cli.run(project=project, args=['-C', alpha_workspace, 'workspace', 'close', alpha_element])
    
    1166
    +    result = cli.run(project=project, args=['-C', alpha_workspace, 'workspace', 'close'] + arg_elm)
    
    1153 1167
         result.assert_success()
    
    1154 1168
     
    
    1155 1169
     
    
    ... ... @@ -1166,11 +1180,13 @@ def test_external_reset_other(cli, datafiles, tmpdir_factory):
    1166 1180
     
    
    1167 1181
     
    
    1168 1182
     @pytest.mark.datafiles(DATA_DIR)
    
    1169
    -def test_external_reset_self(cli, datafiles, tmpdir):
    
    1183
    +@pytest.mark.parametrize("guess_element", [("guess"), ("no-guess")])
    
    1184
    +def test_external_reset_self(cli, datafiles, tmpdir, guess_element):
    
    1170 1185
         element, project, workspace = open_workspace(cli, tmpdir, datafiles, "git", False)
    
    1186
    +    arg_elm = [element] if guess_element == "no-guess" else []
    
    1171 1187
     
    
    1172 1188
         # Command succeeds
    
    1173
    -    result = cli.run(project=project, args=['-C', workspace, 'workspace', 'reset', element])
    
    1189
    +    result = cli.run(project=project, args=['-C', workspace, 'workspace', 'reset'] + arg_elm)
    
    1174 1190
         result.assert_success()
    
    1175 1191
     
    
    1176 1192
         # Successive commands still work (i.e. .bstproject.yaml hasn't been deleted)
    

  • tests/integration/shell.py
    ... ... @@ -358,13 +358,22 @@ def test_integration_devices(cli, tmpdir, datafiles):
    358 358
     # Test that a shell can be opened from an external workspace
    
    359 359
     @pytest.mark.datafiles(DATA_DIR)
    
    360 360
     @pytest.mark.parametrize("build_shell", [("build"), ("nobuild")])
    
    361
    +@pytest.mark.parametrize("guess_element", [("guess"), ("no-guess")])
    
    361 362
     @pytest.mark.skipif(IS_LINUX and not HAVE_BWRAP, reason='Only available with bubblewrap on Linux')
    
    362
    -def test_integration_external_workspace(cli, tmpdir_factory, datafiles, build_shell):
    
    363
    +def test_integration_external_workspace(cli, tmpdir_factory, datafiles, build_shell, guess_element):
    
    363 364
         tmpdir = tmpdir_factory.mktemp("")
    
    364 365
         project = os.path.join(datafiles.dirname, datafiles.basename)
    
    365 366
         element_name = 'autotools/amhello.bst'
    
    366 367
         workspace_dir = os.path.join(str(tmpdir), 'workspace')
    
    367 368
     
    
    369
    +    if guess_element == "guess":
    
    370
    +        # Mutate the project.conf to use a default shell command
    
    371
    +        project_file = os.path.join(project, 'project.conf')
    
    372
    +        config_text = "shell:\n"\
    
    373
    +                      "  command: ['true']\n"
    
    374
    +        with open(project_file, 'a') as f:
    
    375
    +            f.write(config_text)
    
    376
    +
    
    368 377
         result = cli.run(project=project, args=[
    
    369 378
             'workspace', 'open', '--directory', workspace_dir, element_name
    
    370 379
         ])
    
    ... ... @@ -373,9 +382,10 @@ def test_integration_external_workspace(cli, tmpdir_factory, datafiles, build_sh
    373 382
         result = cli.run(project=project, args=['-C', workspace_dir, 'build', element_name])
    
    374 383
         result.assert_success()
    
    375 384
     
    
    376
    -    command = ['shell']
    
    385
    +    command = ['-C', workspace_dir, 'shell']
    
    377 386
         if build_shell == 'build':
    
    378 387
             command.append('--build')
    
    379
    -    command.extend([element_name, '--', 'true'])
    
    388
    +    if guess_element == "no-guess":
    
    389
    +        command.extend([element_name, '--', 'true'])
    
    380 390
         result = cli.run(project=project, cwd=workspace_dir, args=command)
    
    381 391
         result.assert_success()



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