Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests/functional: simplify rose-stem tests #268

Closed
wants to merge 1 commit into from

Conversation

oliver-sanders
Copy link
Member

  • Change class scoped fixtures to module scoped. This avoids test classes and ensures fixtures are only initiated once.
  • Merge fixtures which were only used once in with the test which used them.
  • Remove parameterisations and fail testing code which weren't used by the tests.
  • Remove monkeypatch.delenv where it wasn't needed (monkeypatch resets things by default).

Check List

  • I have read CONTRIBUTING.md and added my name as a Code Contributor.
  • Contains logically grouped changes (else tidy your branch by rebase).
  • Does not contain off-topic changes (use other PRs for other changes).
  • Applied any dependency changes to both setup.cfg (and conda-environment.yml if present).
  • Tests are included (or explain why tests are not needed).
  • CHANGES.md entry included if this is a change that can affect users
  • Cylc-Doc pull request opened if required at cylc/cylc-doc/pull/XXXX.
  • If this is a bug fix, PR should be raised against the relevant ?.?.x branch.

* Change class scoped fixtures to module scoped.
  This avoids test classes and ensures fixtures are only initiated once.
* Merge fixtures which were only used once in with the test which used
  them.
* Remove parameterisations and fail testing code which weren't used by
  the tests.
* Remove monkeypatch.delenv where it wasn't needed (monkeypatch resets
  things by default).
@oliver-sanders oliver-sanders added this to the 1.4.0 milestone Nov 27, 2023
@@ -251,234 +252,83 @@ def _inner_fn(rose_stem_opts, verbosity=verbosity):
yield _inner_fn


@pytest.fixture(scope='class')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Class-scoped fixture wasn't needed as it was only used once (it's a bit too specific to the test to be reusable).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much of the class scoped stuff was done in the name of doing as little re-writing as possible when moving the tests from Stuarts work.

rose_stem_opts = {
'stem_groups': [],
'stem_sources': [
str(setup_stem_repo['workingcopy']), "fcm:foo.x_tr@head"
],
}
yield rose_stem_run_template(rose_stem_opts)
plugin_result = rose_stem_run_template(rose_stem_opts)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure plugin_result is the right name for this, any suggestions?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • stem_outputs
  • stem_variables

Comment on lines -286 to -296
'expected',
[
"run_ok",
"RUN_NAMES=['earl_grey', 'milk', 'sugar', 'spoon', 'cup', 'milk']",
"SOURCE_FOO=\"{workingcopy} fcm:foo.x_tr@head\"",
"HOST_SOURCE_FOO=\"{hostname}:{workingcopy} fcm:foo.x_tr@head\"",
"SOURCE_FOO_BASE=\"{workingcopy}\"\n",
"SOURCE_FOO_BASE=\"{hostname}:{workingcopy}\"\n",
"SOURCE_FOO_REV=\"\"\n",
"SOURCE_FOO_MIRROR=\"fcm:foo.xm/trunk@1\"\n",
]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This parameterisation only defines on variable, expected, which is always run_ok.

I don't think the other stuff did anything?

By removing this, have I killed what this was supposed to be testing?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that's right. Here is how I would rewrite the test

@@ -265,5 +265,5 @@ def test_rose_stem_run_really_basic(rose_stem_run_template, setup_stem_repo):
 
-def rose_stem_run_basic(rose_stem_run_template, setup_stem_repo):
+def test_rose_stem_run_basic(rose_stem_run_template, setup_stem_repo):
     """Check that assorted variables have been exported."""
     rose_stem_opts = {
@@ -277,4 +277,18 @@ def rose_stem_run_basic(rose_stem_run_template, setup_stem_repo):
     assert plugin_result['run_stem'].returncode == 0
 
+    for line in [
+        "RUN_NAMES=['earl_grey', 'milk', 'sugar', 'spoon', 'cup', 'milk']",
+        'SOURCE_FOO="{workingcopy} fcm:foo.x_tr@head"',
+        'HOST_SOURCE_FOO="{hostname}:{workingcopy} fcm:foo.x_tr@head"',
+        'SOURCE_FOO_BASE="{hostname}:{workingcopy}"',
+        'SOURCE_FOO_REV=""',
+        'SOURCE_FOO_MIRROR="fcm:foo.xm/trunk@1"',
+    ]:
+        line = line.format(
+            **plugin_result,
+            hostname=HOST
+        )
+        assert line in plugin_result['jobout_content']

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I had misread that parametrisation, drafted.

Comment on lines -303 to -308
else:
expected = expected.format(
workingcopy=rose_stem_run_basic['workingcopy'],
hostname=HOST
)
assert expected in rose_stem_run_basic['jobout_content']
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expected is always run_ok so this never got run?

assert expected in subdirectory['jobout_content']


@pytest.fixture(scope='class')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you only want a fixture to be initiated once, use the module-scope. The class-scope allows multiple test classes which would initialise this fixture once each.


from cylc.rose.stem import (
RoseStemVersionException,
get_rose_stem_opts,
rose_stem,
)


HOST = get_host().split('.')[0]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This variable doesn't appear to be used any more?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only at lines 306, 355, 392, 431, 471 & 524.

'ROSE_CONF_PATH', str(setup_stem_repo['basetemp'])
)
yield rose_stem_run_template(rose_stem_opts)
monkeymodule.delenv('ROSE_CONF_PATH')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Monkeypatch/module should do this by itself?

Copy link
Member

@wxtim wxtim Nov 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the end of the module. I think we want to remove this now, this should be monekypatch (as you have done!).

@oliver-sanders
Copy link
Member Author

Test failures are now all reinstall tests.

Comment on lines -286 to -296
'expected',
[
"run_ok",
"RUN_NAMES=['earl_grey', 'milk', 'sugar', 'spoon', 'cup', 'milk']",
"SOURCE_FOO=\"{workingcopy} fcm:foo.x_tr@head\"",
"HOST_SOURCE_FOO=\"{hostname}:{workingcopy} fcm:foo.x_tr@head\"",
"SOURCE_FOO_BASE=\"{workingcopy}\"\n",
"SOURCE_FOO_BASE=\"{hostname}:{workingcopy}\"\n",
"SOURCE_FOO_REV=\"\"\n",
"SOURCE_FOO_MIRROR=\"fcm:foo.xm/trunk@1\"\n",
]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that's right. Here is how I would rewrite the test

@@ -265,5 +265,5 @@ def test_rose_stem_run_really_basic(rose_stem_run_template, setup_stem_repo):
 
-def rose_stem_run_basic(rose_stem_run_template, setup_stem_repo):
+def test_rose_stem_run_basic(rose_stem_run_template, setup_stem_repo):
     """Check that assorted variables have been exported."""
     rose_stem_opts = {
@@ -277,4 +277,18 @@ def rose_stem_run_basic(rose_stem_run_template, setup_stem_repo):
     assert plugin_result['run_stem'].returncode == 0
 
+    for line in [
+        "RUN_NAMES=['earl_grey', 'milk', 'sugar', 'spoon', 'cup', 'milk']",
+        'SOURCE_FOO="{workingcopy} fcm:foo.x_tr@head"',
+        'HOST_SOURCE_FOO="{hostname}:{workingcopy} fcm:foo.x_tr@head"',
+        'SOURCE_FOO_BASE="{hostname}:{workingcopy}"',
+        'SOURCE_FOO_REV=""',
+        'SOURCE_FOO_MIRROR="fcm:foo.xm/trunk@1"',
+    ]:
+        line = line.format(
+            **plugin_result,
+            hostname=HOST
+        )
+        assert line in plugin_result['jobout_content']

import pytest
from _pytest.monkeypatch import MonkeyPatch
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
from _pytest.monkeypatch import MonkeyPatch
from pytest import MonkeyPatch

@oliver-sanders oliver-sanders marked this pull request as draft November 27, 2023 16:20
@oliver-sanders oliver-sanders mentioned this pull request Apr 23, 2024
8 tasks
@oliver-sanders
Copy link
Member Author

Superseded by #314

@oliver-sanders oliver-sanders removed this from the 1.4.0 milestone Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants