1 # -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
3 # This Source Code Form is subject to the terms of the Mozilla Public
4 # License, v. 2.0. If a copy of the MPL was not distributed with this
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 from uitest
.framework
import UITestCase
8 from uitest
.uihelper
.common
import get_state_as_dict
9 from uitest
.uihelper
.common
import select_pos
10 from uitest
.uihelper
.calc
import enter_text_to_cell
11 from libreoffice
.calc
.document
import get_sheet_from_doc
12 from uitest
.debug
import sleep
13 from libreoffice
.calc
.document
import get_cell_by_position
14 from libreoffice
.uno
.propertyvalue
import mkPropertyValues
15 import org
.libreoffice
.unotest
18 def get_url_for_data_file(file_name
):
19 return pathlib
.Path(org
.libreoffice
.unotest
.makeCopyFromTDOC(file_name
)).as_uri()
21 class regression(UITestCase
):
22 def test_regression_row(self
):
23 self
._regression
_check
(data_groupedby_column
= False)
25 def test_regression_column(self
):
26 self
._regression
_check
(data_groupedby_column
= True)
28 def _regression_check(self
, data_groupedby_column
= True):
29 calc_doc
= self
.ui_test
.load_file(get_url_for_data_file("regression.ods"))
30 xCalcDoc
= self
.xUITest
.getTopFocusWindow()
31 gridwin
= xCalcDoc
.getChild("grid_window")
32 document
= self
.ui_test
.get_component()
34 # Initially the final check status is "FALSE" (failed).
35 self
.assertEqual(get_cell_by_position(document
, 14, 1, 6).getString(), "FALSE",
36 "Check status must be FALSE before the test")
37 self
._do
_regression
(regression_type
= "LINEAR", data_groupedby_column
= data_groupedby_column
, calc_intercept
= True)
38 self
._do
_regression
(regression_type
= "LINEAR", data_groupedby_column
= data_groupedby_column
, calc_intercept
= False)
39 self
._do
_regression
(regression_type
= "LOG", data_groupedby_column
= data_groupedby_column
)
40 self
._do
_regression
(regression_type
= "POWER", data_groupedby_column
= data_groupedby_column
)
41 self
.assertEqual(get_cell_by_position(document
, 14, 1, 6).getString(), "TRUE",
42 "One of more of the checks failed for data_groupedby_column = {}, manually try with the document".
43 format(data_groupedby_column
))
44 self
.ui_test
.close_doc()
46 def _do_regression(self
, regression_type
, data_groupedby_column
= True, calc_intercept
= True):
47 assert(regression_type
== "LINEAR" or regression_type
== "LOG" or regression_type
== "POWER")
48 self
.ui_test
.execute_modeless_dialog_through_command(".uno:RegressionDialog")
49 xDialog
= self
.xUITest
.getTopFocusWindow()
50 xvariable1rangeedit
= xDialog
.getChild("variable1-range-edit")
51 xvariable2rangeedit
= xDialog
.getChild("variable2-range-edit")
52 xoutputrangeedit
= xDialog
.getChild("output-range-edit")
53 xwithlabelscheck
= xDialog
.getChild("withlabels-check")
54 xgroupedbyrowsradio
= xDialog
.getChild("groupedby-rows-radio")
55 xgroupedbycolumnsradio
= xDialog
.getChild("groupedby-columns-radio")
56 xlinearradio
= xDialog
.getChild("linear-radio")
57 xlogarithmicradio
= xDialog
.getChild("logarithmic-radio")
58 xpowerradio
= xDialog
.getChild("power-radio")
59 xnointerceptcheck
= xDialog
.getChild("nointercept-check")
61 ## Set the X, Y and output ranges
62 xvariable1rangeedit
.executeAction("FOCUS", tuple()) # Without this the range parser does not kick in somehow
63 xvariable1rangeedit
.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
64 xvariable1rangeedit
.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
65 if data_groupedby_column
:
66 xvariable1rangeedit
.executeAction("TYPE", mkPropertyValues({"TEXT":"$DataInColumns.$A$1:$C$11"}))
68 xvariable1rangeedit
.executeAction("TYPE", mkPropertyValues({"TEXT":"$DataInRows.$A$1:$K$3"}))
70 xvariable2rangeedit
.executeAction("FOCUS", tuple()) # Without this the range parser does not kick in somehow
71 xvariable2rangeedit
.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
72 xvariable2rangeedit
.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
73 if data_groupedby_column
:
74 xvariable2rangeedit
.executeAction("TYPE", mkPropertyValues({"TEXT":"$DataInColumns.$D$1:$D$11"}))
76 xvariable2rangeedit
.executeAction("TYPE", mkPropertyValues({"TEXT":"$DataInRows.$A$4:$K$4"}))
77 # The data ranges have labels in them
78 if (get_state_as_dict(xwithlabelscheck
)["Selected"]) == "false":
79 xwithlabelscheck
.executeAction("CLICK", tuple())
81 xoutputrangeedit
.executeAction("FOCUS", tuple()) # Without this the range parser does not kick in somehow
82 xoutputrangeedit
.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
83 xoutputrangeedit
.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
84 if regression_type
== "LINEAR":
86 xoutputrangeedit
.executeAction("TYPE", mkPropertyValues({"TEXT":"$ActualLinear.$A$1"}))
88 xoutputrangeedit
.executeAction("TYPE", mkPropertyValues({"TEXT":"$ActualLinearNoIntercept.$A$1"}))
89 elif regression_type
== "LOG":
90 xoutputrangeedit
.executeAction("TYPE", mkPropertyValues({"TEXT":"$ActualLog.$A$1"}))
92 xoutputrangeedit
.executeAction("TYPE", mkPropertyValues({"TEXT":"$ActualPower.$A$1"}))
94 if data_groupedby_column
:
95 xgroupedbycolumnsradio
.executeAction("CLICK", tuple())
97 xgroupedbyrowsradio
.executeAction("CLICK", tuple())
99 if regression_type
== "LINEAR":
100 xlinearradio
.executeAction("CLICK", tuple())
101 elif regression_type
== "LOG":
102 xlogarithmicradio
.executeAction("CLICK", tuple())
104 xpowerradio
.executeAction("CLICK", tuple())
106 if not calc_intercept
:
107 xnointerceptcheck
.executeAction("CLICK", tuple())
109 xOKBtn
= xDialog
.getChild("ok")
110 self
.ui_test
.close_dialog_through_button(xOKBtn
)
112 def test_regression_cancel(self
):
113 calc_doc
= self
.ui_test
.create_doc_in_start_center("calc")
114 self
.ui_test
.execute_modeless_dialog_through_command(".uno:RegressionDialog")
115 xDialog
= self
.xUITest
.getTopFocusWindow()
116 xCancelBtn
= xDialog
.getChild("cancel")
117 self
.ui_test
.close_dialog_through_button(xCancelBtn
)
119 self
.ui_test
.close_doc()
121 # vim: set shiftwidth=4 softtabstop=4 expandtab: