-
Notifications
You must be signed in to change notification settings - Fork 11
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
Conversation
* 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).
@@ -251,234 +252,83 @@ def _inner_fn(rose_stem_opts, verbosity=verbosity): | |||
yield _inner_fn | |||
|
|||
|
|||
@pytest.fixture(scope='class') |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- stem_outputs
- stem_variables
'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", | ||
] |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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']
There was a problem hiding this comment.
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.
else: | ||
expected = expected.format( | ||
workingcopy=rose_stem_run_basic['workingcopy'], | ||
hostname=HOST | ||
) | ||
assert expected in rose_stem_run_basic['jobout_content'] |
There was a problem hiding this comment.
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') |
There was a problem hiding this comment.
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] |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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') |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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!).
Test failures are now all reinstall tests. |
'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", | ||
] |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from _pytest.monkeypatch import MonkeyPatch | |
from pytest import MonkeyPatch |
Superseded by #314 |
Check List
CONTRIBUTING.md
and added my name as a Code Contributor.setup.cfg
(andconda-environment.yml
if present).CHANGES.md
entry included if this is a change that can affect users?.?.x
branch.