Skip to content

Commit

Permalink
feature.stem installs to workflow name where workflow name is basenam…
Browse files Browse the repository at this point in the history
…e of stem suite

unit test _get_name method
  • Loading branch information
wxtim committed Sep 13, 2022
1 parent 591c245 commit 5928fd4
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ ones in. -->

### Fixes

[#180](https://github.com/cylc/cylc-rose/pull/180) - Rose stem gets stem
suite's basename to use as workflow name when not otherwise set.

[#171](https://github.com/cylc/cylc-rose/pull/171) - Fix bug where Cylc Rose
passed `rose-suite.conf` items commented with `!` or `!!` to Cylc regardless.

Expand Down
2 changes: 1 addition & 1 deletion cylc/rose/stem.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ def _generate_name(self):
basedir = os.path.abspath(self.opts.source)
else:
basedir = os.getcwd()
name = os.path.basename(basedir)
name = os.path.basename(os.path.dirname(basedir))
self.reporter(NameSetEvent(name))
return name

Expand Down
45 changes: 44 additions & 1 deletion tests/unit/test_rose_stem_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
"""Functional tests for top-level function record_cylc_install_options and
"""

import os
import pytest
from types import SimpleNamespace

from cylc.rose.stem import get_source_opt_from_args
from cylc.rose.stem import get_source_opt_from_args, StemRunner


@pytest.mark.parametrize(
Expand Down Expand Up @@ -54,3 +55,45 @@ def test_get_source_opt_from_args(tmp_path, monkeypatch, args, expect):
assert result == expect
else:
assert result == expect.format(tmp_path=str(tmp_path))


class Test_generate_name:
"""Try 3 paths in StemRunner._generate_name.
Contains a setup function for each path.
"""
EXPECT = 'bar'
MSG = 'Suite is named bar'

@staticmethod
def name_from_fcm(monkeypatch):
"""It gets the name from _ascertain_project."""
class MonkeyStemRunner(StemRunner):
def _ascertain_project(self, x):
return ['foo', '/foo/bar/baz']
return MonkeyStemRunner(SimpleNamespace, reporter=print)

@staticmethod
def source_set(monkeypatch):
"""It gets the name from the source opt."""
opts = SimpleNamespace()
opts.source = 'bar/rose-stem'
stemrunner = StemRunner(opts, reporter=print)
return stemrunner

@staticmethod
def source_unset(monkeypatch):
"""It gets the name from the file path."""
opts = SimpleNamespace()
opts.source = ''
monkeypatch.setattr(os, "getcwd", lambda: "/foo/bar/baz")
stemrunner = StemRunner(opts, reporter=print)
return stemrunner

@pytest.mark.parametrize(
'setup', [
'source_set', 'source_unset', 'name_from_fcm'])
def test__generate_name(self, capsys, monkeypatch, setup):
result = getattr(self, setup)(monkeypatch)._generate_name()
assert result == self.EXPECT
assert self.MSG in capsys.readouterr().out

0 comments on commit 5928fd4

Please sign in to comment.