Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion reframe/frontend/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def _validate_source(self, filename):
further tests and finalizes and validation."""

with open(filename, 'r') as f:
source_tree = ast.parse(f.read())
source_tree = ast.parse(f.read(), filename)

validator = RegressionCheckValidator()
validator.visit(source_tree)
Expand Down
6 changes: 6 additions & 0 deletions unittests/resources/checks_unlisted/invalid_syntax_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import reframe as rfm


@rfm.simple_test
class InvalidSyntaxTest(rfm.RegressionTest:
pass
8 changes: 8 additions & 0 deletions unittests/test_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,11 @@ def test_conflicted_checks(self):
def test_load_error(self):
self.assertRaises(OSError, self.loader.load_from_file,
'unittests/resources/checks/foo.py')

def test_load_invalid_sytax(self):
invalid_check = ('unittests/resources/checks_unlisted/'
'invalid_syntax_check.py')
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.