Skip to content

Conversation

@teojgo
Copy link
Contributor

@teojgo teojgo commented Jul 26, 2018

  • Use filter to filter out empty strings before finalizing shell.

  • User raw string to suppress invalid escape sequence warning.

Fixes #407

@teojgo teojgo added this to the Summer sprint milestone Jul 26, 2018
@teojgo teojgo self-assigned this Jul 26, 2018
@teojgo teojgo requested a review from vkarak July 26, 2018 06:49
@codecov-io
Copy link

codecov-io commented Jul 26, 2018

Codecov Report

Merging #410 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #410      +/-   ##
=========================================
+ Coverage    91.2%   91.2%   +<.01%     
=========================================
  Files          70      70              
  Lines        8582    8586       +4     
=========================================
+ Hits         7827    7831       +4     
  Misses        755     755
Impacted Files Coverage Δ
unittests/test_schedulers.py 97.74% <100%> (+0.02%) ⬆️
reframe/core/shell.py 94.73% <100%> (ø) ⬆️
reframe/core/schedulers/slurm.py 57.52% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9d9ba2e...89e12a8. Read the comment docs.



_RFM_TRAP_ERROR = '''
_RFM_TRAP_ERROR = r'''
Copy link
Contributor

Choose a reason for hiding this comment

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

Question: Which python version are you running and you're getting the string warnings?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pycodestyle shows me the warnings regarding invalid escape sequences. You must run with warnings enabled in order to take then from Python.

def finalize(self):
ret = '\n'.join([self.shebang, *self._prolog,
*self._body, *self._epilog])
# Here empty strings are filtered out before joining
Copy link
Contributor

Choose a reason for hiding this comment

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

Write it as "Filter out empty statements before returning". And return directly, without using the stripped_shell variable.

Copy link
Contributor

Choose a reason for hiding this comment

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

Nonetheless, have you found the place that actually generated these empty instructions? Perhaps, we could fix the problem there.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would also expand the shell script generator tests to check this stripping.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, the problem begins from _format_option of reframe/core/schedulers/slurm.py. If the regression test does not set some fields whose default values are None the _format_option will return an empty string at the corresponding line which will be appended to the list of lines passed to ShellScriptGenerator. Thus, when finalizing, during joining with \n all these empty strings will be replaced by empty lines.

Copy link
Contributor

Choose a reason for hiding this comment

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

As discussed offline, I think it's better to fix that in the Slurm job script generator.

Theofilos Manitaras added 2 commits August 2, 2018 09:44
* Use `filter` to filter out empty strings before finalizing shell.

* User raw string to suppress invalid escape sequence warning.
* Perform the filtering of empty strings before emitting the
  slurm preamble.

* Create unittest to test preamble for empty lines.
@teojgo teojgo force-pushed the bugfix/empty_lines_shell branch from 2fc1fef to bc2fe46 Compare August 6, 2018 06:39
@teojgo teojgo changed the title [bugfix] Filter out empty strings before writing shell [bugfix] Filter out empty strings before writing preamble Aug 6, 2018
preamble.append(opt)

return preamble
# Filter out empty statements before returning"
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove the double quotes at the end.

with open(self.testjob.script_filename) as fp:
self.assertIsNotNone(re.search(r'--hint=nomultithread', fp.read()))

def test_no_empty_lines_in_preamble(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

This test is not specific to the Slurm backend. Instead it must be part of the base _TestJob. I am also not sure that you have to set the different attributes to None explicitly, since the default setUp() method sets up a minimal job.

self.testjob.prepare(self.commands, self.environs)
self.assertRaises(JobNotStartedError, self.testjob.finished)

def test_no_empty_lines_in_preamble(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be part of the _TestJob base class. Subclasses need not re-implement this, since it should be the same everywhere.

self.assertRaises(JobNotStartedError, self.testjob.finished)

def test_no_empty_lines_in_preamble(self):
self.setup_job()
Copy link
Contributor

Choose a reason for hiding this comment

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

You should not call setup_job() here, because this sets everything and most probably the following test will have no meaning. I suggest omitting completely this call. In this case, self.testjob will be minimal.

@teojgo
Copy link
Contributor Author

teojgo commented Aug 13, 2018

@jenkins-cscs retry all

@vkarak
Copy link
Contributor

vkarak commented Aug 23, 2018

@jenkins-cscs retry dom

@vkarak vkarak merged commit 3ee445c into master Aug 23, 2018
@vkarak vkarak deleted the bugfix/empty_lines_shell branch August 23, 2018 08:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants