File tree Expand file tree Collapse file tree 4 files changed +30
-10
lines changed
Expand file tree Collapse file tree 4 files changed +30
-10
lines changed Original file line number Diff line number Diff line change 1+ # Licensed under the Apache License, Version 2.0 (the "License");
2+ # you may not use this file except in compliance with the License.
3+ # You may obtain a copy of the License at
4+ #
5+ # http://www.apache.org/licenses/LICENSE-2.0
6+ #
7+ # Unless required by applicable law or agreed to in writing, software
8+ # distributed under the License is distributed on an "AS IS" BASIS,
9+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+ # See the License for the specific language governing permissions and
11+ # limitations under the License.
12+
13+ from twine import __main__ as dunder_main
14+
15+ import pretend
16+
17+
18+ def test_exception_handling (monkeypatch ):
19+ replaced_dispatch = pretend .raiser (KeyError ('foo' ))
20+ monkeypatch .setattr (dunder_main , 'dispatch' , replaced_dispatch )
21+ assert dunder_main .main () == 'KeyError: foo'
Original file line number Diff line number Diff line change 2121
2222
2323def main ():
24- return dispatch (sys .argv [1 :])
24+ try :
25+ return dispatch (sys .argv [1 :])
26+ except Exception as exc :
27+ return '{0}: {1}' .format (
28+ exc .__class__ .__name__ ,
29+ exc .args [0 ],
30+ )
2531
2632
2733if __name__ == "__main__" :
Original file line number Diff line number Diff line change 1515
1616import argparse
1717import os .path
18- import sys
1918
2019from twine import exceptions as exc
2120from twine .package import PackageFile
@@ -137,7 +136,4 @@ def main(args):
137136 args = parser .parse_args (args )
138137
139138 # Call the register function with the args from the command line
140- try :
141- register (** vars (args ))
142- except Exception as exc :
143- sys .exit ("{exc.__class__.__name__}: {exc}" .format (exc = exc ))
139+ register (** vars (args ))
Original file line number Diff line number Diff line change @@ -251,10 +251,7 @@ def main(args):
251251 args = parser .parse_args (args )
252252
253253 # Call the upload function with the arguments from the command line
254- try :
255- upload (** vars (args ))
256- except Exception as exc :
257- sys .exit ("{exc.__class__.__name__}: {exc}" .format (exc = exc ))
254+ upload (** vars (args ))
258255
259256
260257if __name__ == "__main__" :
You can’t perform that action at this time.
0 commit comments