Skip to content

Commit d2f5131

Browse files
authored
Refactor/exceptions (#175)
* refactor and put `to_pymilo_issue` method implementation into `PymiloException` class instead of concrete classes * `autopep8.sh` applied * `CHANGELOG.md` updated
1 parent d3b9857 commit d2f5131

File tree

4 files changed

+22
-56
lines changed

4 files changed

+22
-56
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77
## [Unreleased]
88
### Added
99
### Changed
10+
- `to_pymilo_issue` function in `PymiloException`
1011
- `valid_url_valid_file` testcase added in `test_exceptions.py`
1112
- `valid_url_valid_file` function in `import_exceptions.py`
1213
- `StandardPayload` in `RESTServerCommunicator`

pymilo/exceptions/deserialize_exception.py

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -64,30 +64,3 @@ def to_pymilo_log(self):
6464
if self.meta_data['error_type'] == DeserializationErrorTypes.CORRUPTED_JSON_FILE:
6565
pymilo_report['object']['json_file'] = self.meta_data['json_file']
6666
return pymilo_report
67-
68-
def to_pymilo_issue(self):
69-
"""
70-
Generate an issue form from the populated error.
71-
72-
:return: issue form of the associated error as a string
73-
"""
74-
pymilo_report = self.to_pymilo_log()
75-
help_request = """
76-
\n\nIn order to help us enhance Pymilo's functionality, please open an issue associated with this error and put the message below inside.\n
77-
"""
78-
description = "#### Description\n Pymilo Import failed."
79-
steps_to_produce = "#### Steps/Code to Reproduce\n It is auto-reported from the pymilo logger."
80-
expected_behavior = "#### Expected Behavior\n A successful Pymilo Import."
81-
actual_behavior = "#### Actual Behavior\n Pymilo Import failed."
82-
operating_system = "#### Operating System\n {os}".format(
83-
os=pymilo_report['os']['full-description'])
84-
python_version = "#### Python Version\n {python_version}".format(
85-
python_version=pymilo_report['versions']["python-version"])
86-
pymilo_version = "#### PyMilo Version\n {pymilo_version}".format(
87-
pymilo_version=pymilo_report['versions']["pymilo-version"])
88-
gathered_data = "#### Logged Data\n {logged_data}".format(
89-
logged_data=str(pymilo_report))
90-
91-
full_issue_form = help_request + description + steps_to_produce + expected_behavior + \
92-
actual_behavior + operating_system + python_version + pymilo_version + gathered_data
93-
return full_issue_form

pymilo/exceptions/pymilo_exception.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ def __init__(self, message, meta_data):
2727
self.message = message
2828
self.meta_data = meta_data
2929

30-
# collect All pymilo related data.
3130
def to_pymilo_log(self):
3231
"""
3332
Generate a comprehensive report of the populated error.
@@ -59,13 +58,33 @@ def to_pymilo_log(self):
5958

6059
return pymilo_report
6160

62-
@abstractmethod
6361
def to_pymilo_issue(self):
6462
"""
6563
Generate an issue form from the populated error.
6664
6765
:return: issue form of the associated error as string
6866
"""
67+
pymilo_report = self.to_pymilo_log()
68+
help_request = """
69+
\n\nIn order to help us enhance Pymilo's functionality, please open an issue associated with this error and put the message below inside.\n
70+
"""
71+
associated_pymilo_class = "Export" if "Serialization" in self.message else "Import"
72+
description = "#### Description\n Pymilo {pymilo_class} failed.".format(pymilo_class=associated_pymilo_class)
73+
steps_to_produce = "\n#### Steps/Code to Reproduce\n It is auto-reported from the pymilo logger."
74+
expected_behavior = "\n#### Expected Behavior\n A successful Pymilo {pymilo_class}.".format(
75+
pymilo_class=associated_pymilo_class)
76+
actual_behavior = "\n#### Actual Behavior\n Pymilo {pymilo_class} failed.".format(
77+
pymilo_class=associated_pymilo_class)
78+
operating_system = "#### Operating System\n {os}".format(os=pymilo_report['os']['full-description'])
79+
python_version = "#### Python Version\n {python_version}".format(
80+
python_version=pymilo_report['versions']["python-version"])
81+
pymilo_version = "#### PyMilo Version\n {pymilo_version}".format(
82+
pymilo_version=pymilo_report['versions']["pymilo-version"])
83+
gathered_data = "#### Logged Data\n {logged_data}".format(logged_data=str(pymilo_report))
84+
85+
full_issue_form = help_request + description + steps_to_produce + expected_behavior + \
86+
actual_behavior + operating_system + python_version + pymilo_version + gathered_data
87+
return full_issue_form
6988

7089
def __str__(self):
7190
"""

pymilo/exceptions/serialize_exception.py

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -53,30 +53,3 @@ def to_pymilo_log(self):
5353
pymilo_report = super().to_pymilo_log()
5454
# TODO add any serializable field to `object` field of pymilo_report
5555
return pymilo_report
56-
57-
def to_pymilo_issue(self):
58-
"""
59-
Generate an issue form from the populated error.
60-
61-
:return: issue form of the associated error as string
62-
"""
63-
pymilo_report = self.to_pymilo_log()
64-
help_request = """
65-
\n\nIn order to help us enhance Pymilo's functionality, please open an issue associated with this error and put the message below inside.\n
66-
"""
67-
description = "#### Description\n Pymilo Export failed."
68-
steps_to_produce = "\n#### Steps/Code to Reproduce\n It is auto-reported from the pymilo logger."
69-
expected_behavior = "\n#### Expected Behavior\n A successful Pymilo Export."
70-
actual_behavior = "\n#### Actual Behavior\n Pymilo Export failed."
71-
operating_system = "#### Operating System\n {os}".format(
72-
os=pymilo_report['os']['full-description'])
73-
python_version = "#### Python Version\n {python_version}".format(
74-
python_version=pymilo_report['versions']["python-version"])
75-
pymilo_version = "#### PyMilo Version\n {pymilo_version}".format(
76-
pymilo_version=pymilo_report['versions']["pymilo-version"])
77-
gathered_data = "#### Logged Data\n {logged_data}".format(
78-
logged_data=str(pymilo_report))
79-
80-
full_issue_form = help_request + description + steps_to_produce + expected_behavior + \
81-
actual_behavior + operating_system + python_version + pymilo_version + gathered_data
82-
return full_issue_form

0 commit comments

Comments
 (0)