2016-08-10 19:03:50 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
|
|
import cProfile
|
2016-09-18 14:34:41 +01:00
|
|
|
import os.path
|
|
|
|
|
import shutil
|
2016-08-10 19:03:50 +01:00
|
|
|
import unittest
|
|
|
|
|
from loot_api import Version
|
2016-09-18 17:43:04 +01:00
|
|
|
from loot_api import WrapperVersion
|
2016-08-10 19:03:50 +01:00
|
|
|
from loot_api import GameType
|
2017-03-25 13:50:40 +00:00
|
|
|
from loot_api import SimpleMessage
|
2016-08-10 19:03:50 +01:00
|
|
|
from loot_api import MessageType
|
2017-11-04 17:23:07 +00:00
|
|
|
from loot_api import create_game_handle
|
2016-08-10 19:03:50 +01:00
|
|
|
from loot_api import is_compatible
|
2017-10-17 20:19:39 +01:00
|
|
|
from loot_api import set_logging_callback
|
2017-03-25 13:50:40 +00:00
|
|
|
from loot_api import initialise_locale
|
|
|
|
|
|
2017-10-17 20:19:39 +01:00
|
|
|
def logging_callback(level, message):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
set_logging_callback(logging_callback)
|
2017-03-25 13:50:40 +00:00
|
|
|
initialise_locale("")
|
2016-08-10 19:03:50 +01:00
|
|
|
|
2016-09-18 14:34:41 +01:00
|
|
|
class GameFixture(unittest.TestCase):
|
|
|
|
|
game_path = os.path.join(u'.', u'Oblivion')
|
2016-09-18 20:24:04 +01:00
|
|
|
local_path = os.path.join(u'.', u'local')
|
2016-09-18 14:34:41 +01:00
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
|
data_path = os.path.join(self.game_path, 'Data')
|
|
|
|
|
master_file = os.path.join(data_path, 'Oblivion.esm')
|
|
|
|
|
|
|
|
|
|
os.makedirs(data_path)
|
|
|
|
|
open(master_file, 'a').close()
|
|
|
|
|
|
2016-09-18 20:24:04 +01:00
|
|
|
os.makedirs(self.local_path)
|
|
|
|
|
|
2016-09-18 14:34:41 +01:00
|
|
|
def tearDown(self):
|
|
|
|
|
shutil.rmtree(self.game_path)
|
2016-09-18 20:24:04 +01:00
|
|
|
shutil.rmtree(self.local_path)
|
2016-09-18 14:34:41 +01:00
|
|
|
|
|
|
|
|
class TestLootApi(GameFixture):
|
2016-08-10 19:03:50 +01:00
|
|
|
def test_is_compatible(self):
|
2016-09-18 14:34:41 +01:00
|
|
|
self.assertFalse(is_compatible(0, 9, 0))
|
2017-10-17 20:19:39 +01:00
|
|
|
self.assertTrue(is_compatible(0, 12, 0))
|
2016-08-10 19:03:50 +01:00
|
|
|
|
|
|
|
|
def test_version(self):
|
|
|
|
|
self.assertEqual(Version.major, 0)
|
2017-10-17 20:19:39 +01:00
|
|
|
self.assertEqual(Version.minor, 12)
|
|
|
|
|
self.assertEqual(Version.patch, 0)
|
2016-08-10 19:03:50 +01:00
|
|
|
self.assertNotEqual(Version.revision, u'')
|
2017-10-17 20:19:39 +01:00
|
|
|
self.assertEqual(Version.string(), "0.12.0")
|
2016-08-10 19:03:50 +01:00
|
|
|
|
2016-09-18 17:43:04 +01:00
|
|
|
def test_wrapper_version(self):
|
2017-11-04 12:29:27 +00:00
|
|
|
self.assertEqual(WrapperVersion.major, 3)
|
2017-05-13 08:46:04 +01:00
|
|
|
self.assertEqual(WrapperVersion.minor, 0)
|
2016-12-15 20:38:44 +00:00
|
|
|
self.assertEqual(WrapperVersion.patch, 0)
|
2016-09-18 17:43:04 +01:00
|
|
|
self.assertNotEqual(WrapperVersion.revision, u'')
|
|
|
|
|
self.assertNotEqual(WrapperVersion.revision, Version.revision)
|
2017-11-04 12:29:27 +00:00
|
|
|
self.assertEqual(WrapperVersion.string(), "3.0.0")
|
2016-09-18 17:43:04 +01:00
|
|
|
|
2016-08-10 19:03:50 +01:00
|
|
|
def test_create_db(self):
|
2017-11-04 17:23:07 +00:00
|
|
|
game = create_game_handle(GameType.tes4, self.game_path, self.local_path)
|
|
|
|
|
db = game.get_database()
|
2016-08-10 19:03:50 +01:00
|
|
|
self.assertNotEqual(db, None)
|
|
|
|
|
|
2016-09-18 14:34:41 +01:00
|
|
|
class TestDatabaseInterface(GameFixture):
|
2016-08-10 19:03:50 +01:00
|
|
|
masterlist_path = u'masterlist.yaml'
|
|
|
|
|
|
|
|
|
|
def setUp(self):
|
2016-09-18 14:34:41 +01:00
|
|
|
super(TestDatabaseInterface, self).setUp()
|
|
|
|
|
|
2017-11-04 17:23:07 +00:00
|
|
|
game = create_game_handle(GameType.tes4, self.game_path, self.local_path)
|
|
|
|
|
game.load_current_load_order_state()
|
|
|
|
|
|
|
|
|
|
self.db = game.get_database()
|
2016-08-10 19:03:50 +01:00
|
|
|
|
|
|
|
|
def test_load_lists(self):
|
|
|
|
|
self.db.load_lists(self.masterlist_path, u'')
|
|
|
|
|
|
|
|
|
|
def test_get_plugin_tags(self):
|
|
|
|
|
self.db.load_lists(self.masterlist_path, u'')
|
|
|
|
|
tags = self.db.get_plugin_tags(u'Unofficial Oblivion Patch.esp')
|
|
|
|
|
|
|
|
|
|
self.assertNotEqual(tags, None)
|
|
|
|
|
self.assertFalse(tags.userlist_modified)
|
|
|
|
|
self.assertEqual(tags.added, set([
|
2016-09-18 14:34:41 +01:00
|
|
|
u'Actors.ACBS',
|
|
|
|
|
u'Actors.AIData',
|
|
|
|
|
u'Actors.AIPackages',
|
|
|
|
|
u'Actors.CombatStyle',
|
|
|
|
|
u'Actors.DeathItem',
|
|
|
|
|
u'Actors.Stats',
|
|
|
|
|
u'C.Climate',
|
|
|
|
|
u'C.Light',
|
|
|
|
|
u'C.Music',
|
|
|
|
|
u'C.Name',
|
|
|
|
|
u'C.Owner',
|
|
|
|
|
u'Creatures.Blood',
|
|
|
|
|
u'Delev',
|
|
|
|
|
u'Factions',
|
|
|
|
|
u'Invent',
|
|
|
|
|
u'Names',
|
|
|
|
|
u'NPC.Class',
|
|
|
|
|
u'Relations',
|
|
|
|
|
u'Relev',
|
|
|
|
|
u'Scripts',
|
2016-08-10 19:03:50 +01:00
|
|
|
u'Stats'
|
|
|
|
|
]))
|
|
|
|
|
self.assertEqual(tags.removed, set([u'C.Water']))
|
|
|
|
|
|
|
|
|
|
def test_get_plugin_messages(self):
|
|
|
|
|
self.db.load_lists(self.masterlist_path, u'')
|
|
|
|
|
|
2017-03-25 13:50:40 +00:00
|
|
|
messages = self.db.get_plugin_metadata(u'Oblivion.esm').get_simple_messages(u'en')
|
2016-08-10 19:03:50 +01:00
|
|
|
|
|
|
|
|
self.assertEqual(len(messages), 1)
|
|
|
|
|
self.assertEqual(messages[0].type, MessageType.error)
|
|
|
|
|
self.assertEqual(messages[0].text, u'This must not be activated. However, it can be useful when porting Oblivion mods to Nehrim.')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
unittest.main()
|