Skip to content

Conversation

@teojgo
Copy link
Contributor

@teojgo teojgo commented May 29, 2018

  • Raise a ReframeSyntaxError with a descriptive message if parsing of
    a RegressionTest fails.

  • Create the corresponding unittest

Fixes #267

* Raise a `ReframeSyntaxError` with a descriptive message if parsing of
  a `RegressionTest` fails.

* Create the corresponding unittest.
@teojgo teojgo added this to the ReFrame sprint 2018w20 milestone May 29, 2018
@teojgo teojgo self-assigned this May 29, 2018
@teojgo teojgo requested a review from vkarak May 29, 2018 13:45
except SyntaxError as e:
message = ('\nRegression check syntax error:\n{0}Line: {1}\n'
'File: {2}'.format(e.text, e.lineno, filename))
raise ReframeSyntaxError(message)
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't like very much reraising a real SyntaxError as ReframeSyntaxError. The purpose of the latter is just to denote errors in the usage of the decorators. I agree the name is not very accurate, but I couldn't come up with a better name.

The problem here is firstly conceptual: ReframeSyntaxErrors are ReframeErrors, but a real SyntaxError can never be a ReframeError. Secondly, reraising it differently may hide useful information from real problems.

The solution to this problem is really simple! Just pass a filename argument to parse(). Have a look here.

def test_load_invalid_sytax(self):
self.assertRaises(ReframeSyntaxError, self.loader.load_from_file,
'unittests/resources/checks_unlisted/'
'invalid_syntax_check.py')
Copy link
Contributor

Choose a reason for hiding this comment

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

Here you should check that the filename attribute of the raised SyntaxError is set properly.

@vkarak vkarak changed the title Raise ReframeSyntaxError if check parsing fails Print filename if a test file contains syntax errors May 30, 2018
import reframe.utility as util
from reframe.core.exceptions import NameConflictError, RegressionTestLoadError
from reframe.core.exceptions import (NameConflictError,
RegressionTestLoadError)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do not split the line.

with self.assertRaises(SyntaxError) as e:
self.loader.load_from_file(invalid_check)

self.assertEqual(e.exception.filename, invalid_check)
Copy link
Contributor

Choose a reason for hiding this comment

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

I know that e is visible outside the with statement, but does it make sense to have this assertion outside the with block?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you put the assertion inside the with block, it is not reachable since the with block exits once the exception is thrown.

@vkarak
Copy link
Contributor

vkarak commented Jun 1, 2018

@jenkins-cscs retry dom

@vkarak vkarak merged commit 285baa4 into master Jun 1, 2018
@vkarak vkarak deleted the bugfix/syntax_error_filename branch June 1, 2018 07:58
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.

3 participants