lutris/tests/test_dialogs.py

100 lines
3.5 KiB
Python
Raw Normal View History

2014-08-17 22:30:24 +00:00
import os
2016-08-04 22:49:38 +00:00
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gio, Gtk
2014-08-17 22:30:24 +00:00
from lutris.game import Game
2014-08-18 10:19:36 +00:00
from lutris.config import check_config
2014-10-12 16:54:51 +00:00
# from lutris import settings
2015-11-11 18:48:40 +00:00
from lutris import pga
2014-08-12 23:36:18 +00:00
from lutris.gui import config_dialogs
from lutris.gui.application import Application
2014-08-12 23:36:18 +00:00
from unittest import TestCase
2014-08-12 23:50:25 +00:00
from lutris import runners
2014-08-18 10:02:35 +00:00
TEST_PGA_PATH = os.path.join(os.path.dirname(__file__), 'pga.db')
2014-08-12 23:50:25 +00:00
class TestGameDialogCommon(TestCase):
def test_get_runner_liststore(self):
dlg = config_dialogs.GameDialogCommon()
2015-12-21 19:57:07 +00:00
list_store = dlg._get_runner_liststore()
2015-09-30 17:48:02 +00:00
self.assertTrue(
2017-03-03 19:13:59 +00:00
list_store[1][0].startswith(runners.get_installed()[0].human_name)
2015-09-30 17:48:02 +00:00
)
2015-10-01 10:08:14 +00:00
self.assertEqual(list_store[1][1], runners.get_installed()[0].name)
2014-08-12 23:36:18 +00:00
2014-08-18 10:05:23 +00:00
class TestGameDialog(TestCase):
def setUp(self):
2014-08-18 10:19:36 +00:00
check_config()
lutris_application = Application()
lutris_window = lutris_application.window
self.dlg = config_dialogs.AddGameDialog(lutris_window)
2014-10-12 16:54:51 +00:00
def get_notebook(self):
return self.dlg.vbox.get_children()[0]
def get_viewport(self, index):
scrolled_window = self.get_notebook().get_children()[index]
viewport = scrolled_window.get_children()[0]
return viewport.get_children()[0]
def get_game_box(self):
return self.get_viewport(1)
def get_buttons(self):
2015-10-31 08:50:28 +00:00
notebook = self.dlg.vbox.get_children()[1]
# For some reason, there isn't a ButtonBox on Ubuntu 14.4, weird.
button_box = notebook.get_children()[0]
if button_box.__class__ == Gtk.CheckButton:
button_hbox = notebook.get_children()[1]
else:
button_hbox = button_box.get_children()[1]
self.assertEqual(button_hbox.__class__, Gtk.HBox)
return button_hbox
2014-08-18 10:05:23 +00:00
2014-08-12 23:36:18 +00:00
def test_dialog(self):
2014-10-12 16:54:51 +00:00
self.assertEqual(self.dlg.notebook.get_current_page(), 0)
2014-08-17 22:30:24 +00:00
def test_changing_runner_sets_new_config(self):
2014-10-12 16:54:51 +00:00
label = self.get_notebook().get_children()[1]
2014-08-17 22:30:24 +00:00
self.assertIn('Select a runner', label.get_text())
2014-10-12 16:54:51 +00:00
buttons = self.get_buttons().get_children()
2014-08-17 22:30:24 +00:00
self.assertEqual(buttons[0].get_label(), 'Cancel')
self.assertEqual(buttons[1].get_label(), 'Save')
2014-08-17 22:30:24 +00:00
2015-09-30 17:48:02 +00:00
self.dlg.runner_dropdown.set_active_id('linux')
self.assertEqual(self.dlg.lutris_config.runner_slug, 'linux')
2014-10-12 16:54:51 +00:00
game_box = self.get_game_box()
2015-09-30 17:48:02 +00:00
self.assertEqual(game_box.game.runner_name, 'linux')
2014-10-09 20:20:30 +00:00
exe_box = game_box.get_children()[0].get_children()[0]
exe_field = exe_box.get_children()[1]
2014-08-17 22:30:24 +00:00
self.assertEqual(exe_field.__class__.__name__, 'FileChooserButton')
def test_can_add_game(self):
2014-10-12 16:54:51 +00:00
name_entry = self.dlg.name_entry
2014-08-17 22:30:24 +00:00
name_entry.set_text("Test game")
2015-09-30 17:48:02 +00:00
self.dlg.runner_dropdown.set_active_id('linux')
2014-08-17 22:30:24 +00:00
2014-10-12 16:54:51 +00:00
game_box = self.get_game_box()
2014-10-09 20:20:30 +00:00
exe_box = game_box.get_children()[0].get_children()[0]
exe_label = exe_box.get_children()[0]
2014-08-17 22:30:24 +00:00
self.assertEqual(exe_label.get_text(), "Executable")
test_exe = os.path.abspath(__file__)
2014-10-09 20:20:30 +00:00
exe_field = exe_box.get_children()[1]
2014-08-17 22:30:24 +00:00
exe_field.set_file(Gio.File.new_for_path(test_exe))
exe_field.emit('file-set')
self.assertEqual(exe_field.get_filename(), test_exe)
2014-10-12 16:54:51 +00:00
add_button = self.get_buttons().get_children()[1]
2014-08-17 22:30:24 +00:00
add_button.clicked()
2015-11-11 18:48:40 +00:00
pga_game = pga.get_game_by_field('test-game', 'slug')
self.assertTrue(pga_game)
2015-11-11 18:48:40 +00:00
game = Game(pga_game['id'])
2014-08-17 22:30:24 +00:00
self.assertEqual(game.name, 'Test game')
game.remove(from_library=True)