In my PyQt app I have a main menu, which has the following structure:
Main Menu
|___
|
Language
| |
| Russian
| |
| English
Exit
I want to perform a click on Russian to test if the language is changed. I have a link to language_menu in GUI
[...somewhere in MainWindow...]
self.language_menu = QtGui.QMenu()
[....]
so
from PyQt4 import QtGui, QtCore
from PyQt4.QTest import QTest
from gui import MainWindow
class TestMainWindow(unittest.TestCase):
def setUp(self):
self.app = QtGui.QApplication([])
self.ui = MainWindow()
def tearDown(self):
self.app.deleteLater()
def test_translation(self):
menu = self.ui.language_menu
rus_lang = menu.actions()[0]
QTest.mouseClick(rus_lang, QtCore.Qt.LeftButton)
but it tells me that
argument 1 has unexpected type 'QAction'
How do I do this? Is it even possible?
You can use rus_lang.trigger()
or rus_lang.toggle()
to activate the menu item.