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')
|
|
|
|
|
2015-10-31 21:56:29 +00:00
|
|
|
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
|
2014-10-12 18:07:35 +00:00
|
|
|
from lutris.gui.lutriswindow import LutrisWindow
|
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(
|
2015-10-01 10:08:14 +00:00
|
|
|
list_store[1][0].startswith(runners.get_installed()[0].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()
|
2014-10-12 18:07:35 +00:00
|
|
|
lutris_window = LutrisWindow()
|
2015-10-07 20:25:49 +00:00
|
|
|
self.dlg = config_dialogs.AddGameDialog(lutris_window.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]
|
2015-10-31 22:04:42 +00:00
|
|
|
# For some reason, there isn't a ButtonBox on Ubuntu 14.4, weird.
|
2015-10-31 21:56:29 +00:00
|
|
|
button_box = notebook.get_children()[0]
|
2015-10-31 22:04:42 +00:00
|
|
|
if button_box.__class__ == Gtk.CheckButton:
|
|
|
|
button_hbox = notebook.get_children()[1]
|
|
|
|
else:
|
|
|
|
button_hbox = button_box.get_children()[1]
|
2015-10-31 21:56:29 +00:00
|
|
|
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(), 'Add')
|
|
|
|
|
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')
|
|
|
|
game = Game(pga_game['id'])
|
2014-08-17 22:30:24 +00:00
|
|
|
self.assertEqual(game.name, 'Test game')
|
|
|
|
game.remove(from_library=True)
|