Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Handle coverage file not found error separately #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 20, 2016
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
8 changes: 8 additions & 0 deletions reporter/components/reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
from ..components.payload_validator import PayloadValidator


class CoverageFileNotFound(Exception):
pass
Copy link

Choose a reason for hiding this comment

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

What does this do?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're not allowed to have an empty class definition in Python so this creates a simple subclass of Exception. This seemed like the idiomatic way of defining a custom exception without any special behavior.

Copy link

Choose a reason for hiding this comment

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

Cool thanks!



class Reporter:
def __init__(self, args):
self.args = args
Expand All @@ -21,6 +25,10 @@ def run(self):

"""

if not os.path.isfile(self.args.file):
message = "Coverage file `" + self.args.file + "` file not found. "
raise CoverageFileNotFound(message)

xml_filepath = self.__create_xml_report(self.args.file)
formatter = Formatter(xml_filepath)
payload = formatter.payload()
Expand Down
9 changes: 5 additions & 4 deletions reporter/components/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from ..__init__ import __version__ as reporter_version
from ..components.argument_parser import ArgumentParser
from ..components.payload_validator import InvalidPayload
from ..components.reporter import Reporter
from ..components.reporter import CoverageFileNotFound, Reporter


class Runner:
Expand Down Expand Up @@ -45,11 +45,12 @@ def run(self, args=sys.argv[1:], env=os.environ):
reporter = Reporter(parsed_args)
exit_status = reporter.run()
return exit_status
except CoverageException as e:
except CoverageFileNotFound as e:
return self.__handle_error(
"Coverage file `" + parsed_args.file + "` file not found. "
"Use --file <file> to specifiy an alternate location."
str(e) + "\nUse --file <file> to specifiy an alternate location."
)
except CoverageException as e:
return self.__handle_error(str(e), support=True)
except InvalidPayload as e:
return self.__handle_error("Invalid Payload: " + str(e), support=True)
except requests.exceptions.HTTPError as e:
Expand Down