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/.
8 from uitest
.uihelper
.common
import get_state_as_dict
, get_url_for_data_file
9 from libreoffice
.uno
.propertyvalue
import mkPropertyValues
10 from contextlib
import contextmanager
13 def load_csv_file(UITestCase
, fileName
, bUseDefaultOptions
):
14 with UITestCase
.ui_test
.execute_dialog_through_command(".uno:Open", close_button
="open") as xOpenDialog
:
16 xFileName
= xOpenDialog
.getChild("file_name")
17 xFileName
.executeAction("TYPE", mkPropertyValues({"TEXT": get_url_for_data_file(fileName
)}))
19 xDialog
= UITestCase
.ui_test
.wait_for_top_focus_window('TextImportCsvDialog')
22 if bUseDefaultOptions
:
23 xSeparatedBy
= xDialog
.getChild("toseparatedby")
24 xSeparatedBy
.executeAction("CLICK", tuple())
26 xTextDelimiter
= xDialog
.getChild("textdelimiter")
27 xTextDelimiter
.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
28 xTextDelimiter
.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
29 xTextDelimiter
.executeAction("TYPE", mkPropertyValues({"TEXT": "\""}))
31 setToTrue
= ['tab', 'comma', 'semicolon']
32 for childName
in setToTrue
:
33 xChild
= xDialog
.getChild(childName
)
34 if get_state_as_dict(xChild
)['Selected'] == 'false':
35 xChild
.executeAction("CLICK", tuple())
36 UITestCase
.assertEqual('true', get_state_as_dict(xChild
)['Selected'])
38 setToFalse
= ['space', 'other', 'removespace', 'mergedelimiters',
39 'evaluateformulas', 'quotedfieldastext', 'detectspecialnumbers']
40 for childName
in setToFalse
:
41 xChild
= xDialog
.getChild(childName
)
42 if get_state_as_dict(xChild
)['Selected'] == 'true':
43 xChild
.executeAction("CLICK", tuple())
44 UITestCase
.assertEqual('false', get_state_as_dict(xChild
)['Selected'])
46 if childName
== 'detectspecialnumbers':
47 # if 'Detect special numbers' is false, 'Detect scientific numbers' can be modified
48 xDetectScientific
= xDialog
.getChild('detectscientificnumbers')
49 if get_state_as_dict(xDetectScientific
)['Selected'] == 'false':
50 xDetectScientific
.executeAction("CLICK", tuple())
51 UITestCase
.assertEqual('true', get_state_as_dict(xDetectScientific
)['Selected'])
52 xDetectScientific
.executeAction("CLICK", tuple())
53 UITestCase
.assertEqual('false', get_state_as_dict(xDetectScientific
)['Selected'])
54 # if 'Detect special numbers' is true, 'Detect scientific numbers' is true and disabled
55 xChild
.executeAction("CLICK", tuple())
56 UITestCase
.assertEqual('true', get_state_as_dict(xChild
)['Selected'])
57 UITestCase
.assertEqual('true', get_state_as_dict(xDetectScientific
)['Selected'])
58 UITestCase
.assertEqual('false', get_state_as_dict(xDetectScientific
)['Enabled'])
59 xChild
.executeAction("CLICK", tuple())
61 UITestCase
.assertEqual('1', get_state_as_dict(xDialog
.getChild("fromrow"))['Text'])
65 xOK
= xDialog
.getChild('ok')
66 with UITestCase
.ui_test
.wait_until_component_loaded():
67 UITestCase
.ui_test
.close_dialog_through_button(xOK
)