1 # -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
3 # This file is part of the LibreOffice project.
5 # This Source Code Form is subject to the terms of the Mozilla Public
6 # License, v. 2.0. If a copy of the MPL was not distributed with this
7 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 from uitest
.framework
import UITestCase
10 from uitest
.uihelper
.common
import get_state_as_dict
, get_url_for_data_file
12 from libreoffice
.calc
.document
import get_cell_by_position
13 from libreoffice
.uno
.propertyvalue
import mkPropertyValues
16 class regression(UITestCase
):
17 def test_regression_row(self
):
18 self
._regression
_check
(data_groupedby_column
= False)
20 def test_regression_column(self
):
21 self
._regression
_check
(data_groupedby_column
= True)
23 def _regression_check(self
, data_groupedby_column
= True):
24 with self
.ui_test
.load_file(get_url_for_data_file("regression.ods")) as calc_doc
:
25 # Initially the final check status is "FALSE" (failed).
26 self
.assertEqual(get_cell_by_position(calc_doc
, 14, 1, 6).getString(), "FALSE",
27 "Check status must be FALSE before the test")
28 self
._do
_regression
(regression_type
= "LINEAR", data_groupedby_column
= data_groupedby_column
, calc_intercept
= True)
29 self
._do
_regression
(regression_type
= "LINEAR", data_groupedby_column
= data_groupedby_column
, calc_intercept
= False)
30 self
._do
_regression
(regression_type
= "LOG", data_groupedby_column
= data_groupedby_column
)
31 self
._do
_regression
(regression_type
= "POWER", data_groupedby_column
= data_groupedby_column
)
32 self
.assertEqual(get_cell_by_position(calc_doc
, 14, 1, 6).getString(), "TRUE",
33 "One of more of the checks failed for data_groupedby_column = {}, manually try with the calc_doc".
34 format(data_groupedby_column
))
36 def _do_regression(self
, regression_type
, data_groupedby_column
= True, calc_intercept
= True):
37 assert(regression_type
== "LINEAR" or regression_type
== "LOG" or regression_type
== "POWER")
38 with self
.ui_test
.execute_modeless_dialog_through_command(".uno:RegressionDialog") as xDialog
:
39 xvariable1rangeedit
= xDialog
.getChild("variable1-range-edit")
40 xvariable2rangeedit
= xDialog
.getChild("variable2-range-edit")
41 xoutputrangeedit
= xDialog
.getChild("output-range-edit")
42 xwithlabelscheck
= xDialog
.getChild("withlabels-check")
43 xgroupedbyrowsradio
= xDialog
.getChild("groupedby-rows-radio")
44 xgroupedbycolumnsradio
= xDialog
.getChild("groupedby-columns-radio")
45 xlinearradio
= xDialog
.getChild("linear-radio")
46 xlogarithmicradio
= xDialog
.getChild("logarithmic-radio")
47 xpowerradio
= xDialog
.getChild("power-radio")
48 xnointerceptcheck
= xDialog
.getChild("nointercept-check")
50 ## Set the X, Y and output ranges
51 xvariable1rangeedit
.executeAction("FOCUS", tuple()) # Without this the range parser does not kick in somehow
52 xvariable1rangeedit
.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
53 xvariable1rangeedit
.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
54 if data_groupedby_column
:
55 xvariable1rangeedit
.executeAction("TYPE", mkPropertyValues({"TEXT":"$DataInColumns.$A$1:$C$11"}))
57 xvariable1rangeedit
.executeAction("TYPE", mkPropertyValues({"TEXT":"$DataInRows.$A$1:$K$3"}))
59 xvariable2rangeedit
.executeAction("FOCUS", tuple()) # Without this the range parser does not kick in somehow
60 xvariable2rangeedit
.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
61 xvariable2rangeedit
.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
62 if data_groupedby_column
:
63 xvariable2rangeedit
.executeAction("TYPE", mkPropertyValues({"TEXT":"$DataInColumns.$D$1:$D$11"}))
65 xvariable2rangeedit
.executeAction("TYPE", mkPropertyValues({"TEXT":"$DataInRows.$A$4:$K$4"}))
66 # The data ranges have labels in them
67 if (get_state_as_dict(xwithlabelscheck
)["Selected"]) == "false":
68 xwithlabelscheck
.executeAction("CLICK", tuple())
70 xoutputrangeedit
.executeAction("FOCUS", tuple()) # Without this the range parser does not kick in somehow
71 xoutputrangeedit
.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
72 xoutputrangeedit
.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
73 if regression_type
== "LINEAR":
75 xoutputrangeedit
.executeAction("TYPE", mkPropertyValues({"TEXT":"$ActualLinear.$A$1"}))
77 xoutputrangeedit
.executeAction("TYPE", mkPropertyValues({"TEXT":"$ActualLinearNoIntercept.$A$1"}))
78 elif regression_type
== "LOG":
79 xoutputrangeedit
.executeAction("TYPE", mkPropertyValues({"TEXT":"$ActualLog.$A$1"}))
81 xoutputrangeedit
.executeAction("TYPE", mkPropertyValues({"TEXT":"$ActualPower.$A$1"}))
83 if data_groupedby_column
:
84 xgroupedbycolumnsradio
.executeAction("CLICK", tuple())
86 xgroupedbyrowsradio
.executeAction("CLICK", tuple())
88 if regression_type
== "LINEAR":
89 xlinearradio
.executeAction("CLICK", tuple())
90 elif regression_type
== "LOG":
91 xlogarithmicradio
.executeAction("CLICK", tuple())
93 xpowerradio
.executeAction("CLICK", tuple())
95 if not calc_intercept
:
96 xnointerceptcheck
.executeAction("CLICK", tuple())
99 def test_regression_cancel(self
):
100 with self
.ui_test
.create_doc_in_start_center("calc"):
101 with self
.ui_test
.execute_modeless_dialog_through_command(".uno:RegressionDialog", close_button
="cancel"):
104 # vim: set shiftwidth=4 softtabstop=4 expandtab: