def test_rose_fileinstall_exception(tmp_path, monkeypatch): def broken(): raise FileNotFoundError('Any Old Error') import os monkeypatch.setattr(os, 'getcwd', broken) (tmp_path / 'rose-suite.conf').touch() with pytest.raises(FileNotFoundError): rose_fileinstall(srcdir=tmp_path, rundir=tmp_path)
def test_functional_rose_database_dumped_correctly(tmp_path): srcdir = (tmp_path / 'srcdir') rundir = (tmp_path / 'rundir') for dir_ in [srcdir, rundir]: dir_.mkdir() (srcdir / 'rose-suite.conf').touch() # sidestep test for conf existance (rundir / 'nicest_work_of.nature').touch() (rundir / 'rose-suite.conf').write_text("[file:Gnu]\nsrc=nicest_work_of.nature\n") (rundir / 'cylc.flow').touch() rose_fileinstall(srcdir=srcdir, rundir=rundir) assert (rundir / '.rose-config_processors-file.db').is_file()
def test_functional_rose_database_dumped_errors(tmp_path): srcdir = (tmp_path / 'srcdir') srcdir.mkdir() (srcdir / 'nicest_work_of.nature').touch() (srcdir / 'rose-suite.conf').write_text("[file:Gnu]\nsrc=nicest_work_of.nature\n") (srcdir / 'cylc.flow').touch() assert rose_fileinstall(srcdir=Path('/this/path/goes/nowhere')) is False
def test_functional_record_cylc_install_options(monkeypatch, tmp_path, opts, files, env_inserts): """It works the way the proposal says it should. TODO: Once the the dump of the final rose-suite.conf is done then this should be expanded to test that too. """ # Pin down the results of the function used to provide a timestamp. def fake(*arg, **kwargs): return '18151210T0000Z' monkeypatch.setattr(DateTimeOperator, 'process_time_point_str', fake) testdir = tmp_path / 'test' refdir = tmp_path / 'ref' # Set up existing files, should these exist: for fname, content in files.items(): path = tmp_path / fname path.parent.mkdir(parents=True, exist_ok=True) path.write_text(content) # Set any environment variables we require: for envvar, val in env_inserts.items(): monkeypatch.setenv(envvar, val) loader = ConfigLoader() # Run the entry point top-level function: rose_suite_cylc_install_node, rose_suite_opts_node = \ record_cylc_install_options( rundir=testdir, opts=opts, srcdir=testdir ) rose_fileinstall(rundir=testdir, opts=opts, srcdir=testdir) ritems = sorted([i.relative_to(refdir) for i in refdir.rglob('*')]) titems = sorted([i.relative_to(testdir) for i in testdir.rglob('*')]) assert titems == ritems for counter, item in enumerate(titems): output = testdir / item reference = refdir / ritems[counter] if output.is_file(): assert_rose_conf_full_equal(loader.load(str(output)), loader.load(str(reference)), no_ignore=False)
def test_rose_fileinstall_uses_suite_defines(tmp_path): # Setup source and destination dirs, including the file ``installme``: srcdir = tmp_path / 'source' destdir = tmp_path / 'dest' [dir_.mkdir() for dir_ in [srcdir, destdir]] (destdir / 'rose-suite.conf').touch() (srcdir / 'rose-suite.conf').touch() (srcdir / 'installme').write_text('Galileo No! We will not let you go.') # Create an SimpleNamespace pretending to be the options: opts = SimpleNamespace( opt_conf_keys='', defines=[f'[file:installedme]source={str(srcdir)}/installme'], define_suites=[], clear_rose_install_opts=False) # Run both record_cylc_install options and fileinstall. record_cylc_install_options(opts=opts, rundir=destdir) rose_fileinstall(srcdir, opts, destdir) assert (destdir / 'installedme').read_text() == \ 'Galileo No! We will not let you go.'
def test_rose_fileinstall_no_config_in_folder(): # It returns false if no rose-suite.conf assert rose_fileinstall(Path('/dev/null')) is False