Skip to content
This repository was archived by the owner on Oct 1, 2019. It is now read-only.

Commit

Permalink
Improve raise printing (#66)
Browse files Browse the repository at this point in the history
* Add broken tests for #65

* Add long raise test

* Fix typo

* Improve raise printing

* Add another test for raise

* Use groupConcat and indentConcat
  • Loading branch information
patrick91 authored and FuegoFro committed May 11, 2018
1 parent 398b77a commit 9b62d41
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/printer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1074,7 +1074,15 @@ function genericPrint(path, options, print) {
// on python2 exc is called type
const type = n.type ? "type" : "exc";

return group(concat(["raise", line, path.call(print, type)]));
return concat([
"raise",
groupConcat([
ifBreak(" (", " "),
indentConcat([softline, path.call(print, type)]),
softline,
ifBreak(")")
])
]);
}

case "Return": {
Expand Down
95 changes: 95 additions & 0 deletions tests/python_raise/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`raise.py 1`] = `
raise
raise ValueError
raise ValueError("error")
raise NotImplementedError('example.')
raise forms.ValidationError(
self.error_messages['invalid_login'],
code='invalid_login',
params={
'username': self.username_field.verbose_name
}
)
raise SomeErrorWithAReallyReallyVeryVeryExtremelyExtensivelyLongNameSoItBreaks()
raise NotImplementedError(
'The SimpleListFilter.lookups() method must be overridden to '
'return a list of tuples (value, verbose value).'
)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
raise
raise ValueError
raise ValueError("error")
raise NotImplementedError("example.")
raise (
forms.ValidationError(self.error_messages[
"invalid_login"
], code="invalid_login", params={
"username": self.username_field.verbose_name
})
)
raise (
SomeErrorWithAReallyReallyVeryVeryExtremelyExtensivelyLongNameSoItBreaks()
)
raise (
NotImplementedError('The SimpleListFilter.lookups() method must be overridden to '
'return a list of tuples (value, verbose value).')
)
`;

exports[`raise.py 2`] = `
raise
raise ValueError
raise ValueError("error")
raise NotImplementedError('example.')
raise forms.ValidationError(
self.error_messages['invalid_login'],
code='invalid_login',
params={
'username': self.username_field.verbose_name
}
)
raise SomeErrorWithAReallyReallyVeryVeryExtremelyExtensivelyLongNameSoItBreaks()
raise NotImplementedError(
'The SimpleListFilter.lookups() method must be overridden to '
'return a list of tuples (value, verbose value).'
)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
raise
raise ValueError
raise ValueError("error")
raise NotImplementedError("example.")
raise (
forms.ValidationError(self.error_messages[
"invalid_login"
], code="invalid_login", params={
"username": self.username_field.verbose_name
})
)
raise (
SomeErrorWithAReallyReallyVeryVeryExtremelyExtensivelyLongNameSoItBreaks()
)
raise (
NotImplementedError('The SimpleListFilter.lookups() method must be overridden to '
'return a list of tuples (value, verbose value).')
)
`;
2 changes: 2 additions & 0 deletions tests/python_raise/jsfmt.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
run_spec(__dirname, ["python"], { pythonVersion: "2" });
run_spec(__dirname, ["python"], { pythonVersion: "3" });
20 changes: 20 additions & 0 deletions tests/python_raise/raise.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
raise
raise ValueError
raise ValueError("error")

raise NotImplementedError('example.')

raise forms.ValidationError(
self.error_messages['invalid_login'],
code='invalid_login',
params={
'username': self.username_field.verbose_name
}
)

raise SomeErrorWithAReallyReallyVeryVeryExtremelyExtensivelyLongNameSoItBreaks()

raise NotImplementedError(
'The SimpleListFilter.lookups() method must be overridden to '
'return a list of tuples (value, verbose value).'
)

0 comments on commit 9b62d41

Please sign in to comment.