Skip to content

Commit

Permalink
Merge pull request #2584 from janezd/fix-report-pickle
Browse files Browse the repository at this point in the history
[FIX] Fix saving reports on Python 3.6
  • Loading branch information
astaric authored Sep 13, 2017
2 parents cf515f9 + 1caa813 commit 0b448ca
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Orange/canvas/report/owreport.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ def __init__(self, name, html, scheme, module, icon_name, comment=""):
self.id = id(icon)
super().__init__(icon, name)

def __getnewargs__(self):
return (self.name, self.html, self.scheme, self.module, self.icon_name,
self.comment)


class ReportItemModel(QStandardItemModel):
def __init__(self, rows, columns, parent=None):
Expand Down
25 changes: 24 additions & 1 deletion Orange/canvas/report/tests/test_report.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import unittest
from unittest import mock
from importlib import import_module
import os
import warnings
import tempfile

import AnyQt
from AnyQt.QtGui import QFont, QBrush
Expand Down Expand Up @@ -116,7 +118,7 @@ def test_report_table(self):
'font-weight:normal;text-align:right;vertical-align:middle;">2</td>'
'</tr></table>')

def test_save_report(self):
def test_save_report_permission(self):
"""
Permission Error may occur when trying to save report.
GH-2147
Expand All @@ -132,6 +134,23 @@ def test_save_report(self):
unittest.mock.patch(patch_target_3, return_value=True):
rep.save_report()

def test_save_report(self):
rep = OWReport.get_instance()
file = self.create_widget(OWFile)
file.create_report_html()
rep.make_report(file)
temp_dir = tempfile.mkdtemp()
temp_name = os.path.join(temp_dir, "f.report")
try:
with mock.patch("AnyQt.QtWidgets.QFileDialog.getSaveFileName",
return_value=(temp_name, 0)), \
mock.patch("AnyQt.QtWidgets.QMessageBox.exec_",
return_value=True):
rep.save_report()
finally:
os.remove(temp_name)
os.rmdir(temp_dir)


class TestReportWidgets(WidgetTest):
model_widgets = MODEL_WIDGETS
Expand Down Expand Up @@ -220,3 +239,7 @@ def test_report_widgets_all(self):
self.unsu_widgets + self.dist_widgets + self.visu_widgets + \
self.spec_widgets
self._create_report(widgets, rep, None)


if __name__ == "__main__":
unittest.main()

0 comments on commit 0b448ca

Please sign in to comment.