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
.calc
import enter_text_to_cell
11 from uitest
.uihelper
.common
import get_state_as_dict
13 from libreoffice
.calc
.document
import get_cell_by_position
14 from libreoffice
.uno
.propertyvalue
import mkPropertyValues
17 class sampling(UITestCase
):
18 def test_statistic_sampling(self
):
19 with self
.ui_test
.create_doc_in_start_center("calc") as document
:
20 xCalcDoc
= self
.xUITest
.getTopFocusWindow()
21 gridwin
= xCalcDoc
.getChild("grid_window")
23 enter_text_to_cell(gridwin
, "A1", "11")
24 enter_text_to_cell(gridwin
, "A2", "12")
25 enter_text_to_cell(gridwin
, "A3", "13")
26 enter_text_to_cell(gridwin
, "A4", "14")
27 enter_text_to_cell(gridwin
, "A5", "15")
28 enter_text_to_cell(gridwin
, "A6", "16")
29 enter_text_to_cell(gridwin
, "A7", "17")
30 enter_text_to_cell(gridwin
, "A8", "18")
31 enter_text_to_cell(gridwin
, "A9", "19")
33 enter_text_to_cell(gridwin
, "B1", "21")
34 enter_text_to_cell(gridwin
, "B2", "22")
35 enter_text_to_cell(gridwin
, "B3", "23")
36 enter_text_to_cell(gridwin
, "B4", "24")
37 enter_text_to_cell(gridwin
, "B5", "25")
38 enter_text_to_cell(gridwin
, "B6", "26")
39 enter_text_to_cell(gridwin
, "B7", "27")
40 enter_text_to_cell(gridwin
, "B8", "28")
41 enter_text_to_cell(gridwin
, "B9", "29")
43 enter_text_to_cell(gridwin
, "C1", "31")
44 enter_text_to_cell(gridwin
, "C2", "32")
45 enter_text_to_cell(gridwin
, "C3", "33")
46 enter_text_to_cell(gridwin
, "C4", "34")
47 enter_text_to_cell(gridwin
, "C5", "35")
48 enter_text_to_cell(gridwin
, "C6", "36")
49 enter_text_to_cell(gridwin
, "C7", "37")
50 enter_text_to_cell(gridwin
, "C8", "38")
51 enter_text_to_cell(gridwin
, "C9", "39")
52 gridwin
.executeAction("SELECT", mkPropertyValues({"RANGE": "A1:C9"}))
53 with self
.ui_test
.execute_modeless_dialog_through_command(".uno:SamplingDialog") as xDialog
:
54 xinputrangeedit
= xDialog
.getChild("input-range-edit")
55 xoutputrangeedit
= xDialog
.getChild("output-range-edit")
56 xperiodicmethodradio
= xDialog
.getChild("periodic-method-radio")
57 xperiodspin
= xDialog
.getChild("period-spin")
59 xinputrangeedit
.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
60 xinputrangeedit
.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
61 xinputrangeedit
.executeAction("TYPE", mkPropertyValues({"TEXT":"$Sheet1.$A$1:$C$9"}))
63 xoutputrangeedit
.executeAction("TYPE", mkPropertyValues({"TEXT":"$Sheet1.$F$1"}))
65 xperiodicmethodradio
.executeAction("CLICK", tuple())
67 xperiodspin
.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
68 xperiodspin
.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
69 xperiodspin
.executeAction("TYPE", mkPropertyValues({"TEXT":"2"}))
71 self
.assertEqual(get_cell_by_position(document
, 0, 5, 0).getValue(), 12)
72 self
.assertEqual(get_cell_by_position(document
, 0, 5, 1).getValue() , 14)
73 self
.assertEqual(get_cell_by_position(document
, 0, 5, 2).getValue() , 16)
74 self
.assertEqual(get_cell_by_position(document
, 0, 5, 3).getValue() , 18)
76 self
.assertEqual(get_cell_by_position(document
, 0, 6, 0).getValue(), 22)
77 self
.assertEqual(get_cell_by_position(document
, 0, 6, 1).getValue() , 24)
78 self
.assertEqual(get_cell_by_position(document
, 0, 6, 2).getValue() , 26)
79 self
.assertEqual(get_cell_by_position(document
, 0, 6, 3).getValue() , 28)
81 self
.assertEqual(get_cell_by_position(document
, 0, 7, 0).getValue(), 32)
82 self
.assertEqual(get_cell_by_position(document
, 0, 7, 1).getValue() , 34)
83 self
.assertEqual(get_cell_by_position(document
, 0, 7, 2).getValue() , 36)
84 self
.assertEqual(get_cell_by_position(document
, 0, 7, 3).getValue() , 38)
86 self
.xUITest
.executeCommand(".uno:Undo")
87 self
.assertEqual(get_cell_by_position(document
, 0, 5, 0).getValue(), 0)
88 self
.assertEqual(get_cell_by_position(document
, 0, 5, 1).getValue() , 0)
89 self
.assertEqual(get_cell_by_position(document
, 0, 5, 2).getValue() , 0)
90 self
.assertEqual(get_cell_by_position(document
, 0, 5, 3).getValue() , 0)
92 self
.assertEqual(get_cell_by_position(document
, 0, 6, 0).getValue(), 0)
93 self
.assertEqual(get_cell_by_position(document
, 0, 6, 1).getValue() , 0)
94 self
.assertEqual(get_cell_by_position(document
, 0, 6, 2).getValue() , 0)
95 self
.assertEqual(get_cell_by_position(document
, 0, 6, 3).getValue() , 0)
97 self
.assertEqual(get_cell_by_position(document
, 0, 7, 0).getValue(), 0)
98 self
.assertEqual(get_cell_by_position(document
, 0, 7, 1).getValue() , 0)
99 self
.assertEqual(get_cell_by_position(document
, 0, 7, 2).getValue() , 0)
100 self
.assertEqual(get_cell_by_position(document
, 0, 7, 3).getValue() , 0)
103 with self
.ui_test
.execute_modeless_dialog_through_command(".uno:SamplingDialog", close_button
="cancel"):
106 def test_tdf142986(self
):
107 with self
.ui_test
.create_doc_in_start_center("calc") as calc_doc
:
108 xCalcDoc
= self
.xUITest
.getTopFocusWindow()
109 gridwin
= xCalcDoc
.getChild("grid_window")
111 gridwin
.executeAction("SELECT", mkPropertyValues({"RANGE": "A1:A200"}))
112 with self
.ui_test
.execute_dialog_through_command(".uno:FillSeries") as xDialog
:
113 xStartValue
= xDialog
.getChild("startValue")
114 xStartValue
.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
115 xStartValue
.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
116 xStartValue
.executeAction("TYPE", mkPropertyValues({"TEXT":"1"}))
118 xIncrement
= xDialog
.getChild("increment")
119 xIncrement
.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
120 xIncrement
.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
121 xIncrement
.executeAction("TYPE", mkPropertyValues({"TEXT":"1"}))
123 self
.assertEqual(get_cell_by_position(calc_doc
, 0, 0, 199).getValue(), 200)
125 with self
.ui_test
.execute_modeless_dialog_through_command(".uno:SamplingDialog") as xDialog
:
126 xInputRangeEdit
= xDialog
.getChild("input-range-edit")
127 xOutputRangeEdit
= xDialog
.getChild("output-range-edit")
128 xRandomMethodRadio
= xDialog
.getChild("random-method-radio")
129 xSampleSizeSpin
= xDialog
.getChild("sample-size-spin")
131 self
.assertEqual("$Sheet1.$A$1:$A$200", get_state_as_dict(xInputRangeEdit
)['Text'])
133 xOutputRangeEdit
.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
134 xOutputRangeEdit
.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
135 xOutputRangeEdit
.executeAction("TYPE", mkPropertyValues({"TEXT":"$B$1"}))
137 xRandomMethodRadio
.executeAction("CLICK", tuple())
139 xSampleSizeSpin
.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
140 xSampleSizeSpin
.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
141 xSampleSizeSpin
.executeAction("TYPE", mkPropertyValues({"TEXT":"200"}))
144 self
.assertTrue(get_cell_by_position(calc_doc
, 0, 1, i
).getValue() != 0.0,
145 "Value in cell B" + str(i
) + " shouldn't be equal to 0.0")
147 # vim: set shiftwidth=4 softtabstop=4 expandtab: