2016-08-10 19:03:50 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
|
|
import cProfile
|
2019-03-25 08:38:07 +00:00
|
|
|
import os
|
2016-09-18 14:34:41 +01:00
|
|
|
import os.path
|
|
|
|
|
import shutil
|
2019-03-25 08:38:07 +00:00
|
|
|
import sys
|
2016-08-10 19:03:50 +01:00
|
|
|
import unittest
|
2019-03-25 08:38:07 +00:00
|
|
|
|
|
|
|
|
sys.path.append(os.getcwd())
|
|
|
|
|
|
2016-08-10 19:03:50 +01:00
|
|
|
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
|
2019-03-25 09:01:29 +00:00
|
|
|
from loot_api import PluginCleanliness
|
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-12-30 15:27:48 +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))
|
2018-12-12 19:33:21 +00:00
|
|
|
self.assertTrue(is_compatible(0, 14, 0))
|
2016-08-10 19:03:50 +01:00
|
|
|
|
|
|
|
|
def test_version(self):
|
|
|
|
|
self.assertEqual(Version.major, 0)
|
2018-12-12 19:33:21 +00:00
|
|
|
self.assertEqual(Version.minor, 14)
|
2019-03-25 09:47:03 +00:00
|
|
|
self.assertEqual(Version.patch, 5)
|
2016-08-10 19:03:50 +01:00
|
|
|
self.assertNotEqual(Version.revision, u'')
|
2019-03-25 09:47:03 +00:00
|
|
|
self.assertEqual(Version.string(), "0.14.5")
|
2016-08-10 19:03:50 +01:00
|
|
|
|
2016-09-18 17:43:04 +01:00
|
|
|
def test_wrapper_version(self):
|
2019-01-12 17:14:12 +00:00
|
|
|
self.assertEqual(WrapperVersion.major, 4)
|
|
|
|
|
self.assertEqual(WrapperVersion.minor, 0)
|
2019-01-27 14:53:14 +00:00
|
|
|
self.assertEqual(WrapperVersion.patch, 1)
|
2016-09-18 17:43:04 +01:00
|
|
|
self.assertNotEqual(WrapperVersion.revision, u'')
|
|
|
|
|
self.assertNotEqual(WrapperVersion.revision, Version.revision)
|
2019-01-27 14:53:14 +00:00
|
|
|
self.assertEqual(WrapperVersion.string(), "4.0.1")
|
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):
|
2019-03-25 08:38:07 +00:00
|
|
|
masterlist_path = os.path.join(os.path.dirname(__file__), u'masterlist.yaml')
|
2016-08-10 19:03:50 +01:00
|
|
|
|
|
|
|
|
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.')
|
|
|
|
|
|
2019-03-25 09:01:29 +00:00
|
|
|
def test_get_plugin_cleanliness_should_be_unknown_if_no_dirty_or_clean_metadata_exists(self):
|
|
|
|
|
self.db.load_lists(self.masterlist_path, u'')
|
|
|
|
|
|
|
|
|
|
cleanliness = self.db.get_plugin_cleanliness(u'unknown.esp')
|
|
|
|
|
|
|
|
|
|
self.assertEqual(cleanliness, PluginCleanliness.unknown)
|
|
|
|
|
|
|
|
|
|
def test_get_plugin_cleanliness_should_be_unknown_if_dirty_and_clean_metadata_exists(self):
|
|
|
|
|
self.db.load_lists(self.masterlist_path, u'')
|
|
|
|
|
|
|
|
|
|
cleanliness = self.db.get_plugin_cleanliness(u'clean_and_dirty.esp')
|
|
|
|
|
|
|
|
|
|
self.assertEqual(cleanliness, PluginCleanliness.unknown)
|
|
|
|
|
|
|
|
|
|
def test_get_plugin_cleanliness_should_be_clean_if_only_clean_metadata_exists(self):
|
|
|
|
|
self.db.load_lists(self.masterlist_path, u'')
|
|
|
|
|
|
|
|
|
|
cleanliness = self.db.get_plugin_cleanliness(u'clean.esp')
|
|
|
|
|
|
|
|
|
|
self.assertEqual(cleanliness, PluginCleanliness.clean)
|
|
|
|
|
|
|
|
|
|
def test_get_plugin_cleanliness_should_be_dirty_if_only_dirty_metadata_exists(self):
|
|
|
|
|
self.db.load_lists(self.masterlist_path, u'')
|
|
|
|
|
|
|
|
|
|
cleanliness = self.db.get_plugin_cleanliness(u'dirty.esp')
|
|
|
|
|
|
|
|
|
|
self.assertEqual(cleanliness, PluginCleanliness.dirty)
|
|
|
|
|
|
|
|
|
|
def test_get_plugin_cleanliness_should_be_do_not_clean_if_dirty_do_not_clean_info_exists(self):
|
|
|
|
|
self.db.load_lists(self.masterlist_path, u'')
|
|
|
|
|
|
|
|
|
|
cleanliness = self.db.get_plugin_cleanliness(u'do_not_clean.esp')
|
|
|
|
|
|
|
|
|
|
self.assertEqual(cleanliness, PluginCleanliness.do_not_clean)
|
2016-08-10 19:03:50 +01:00
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
unittest.main()
|