Skip to content

Commit

Permalink
Fix broken/failing tests and implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Sheeo committed Dec 3, 2014
1 parent 8595d27 commit 62c9e24
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 26 deletions.
8 changes: 6 additions & 2 deletions src/fa/game_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,12 @@ def __init__(self, engine, main_mod, mods=None, _map=None):
@staticmethod
def from_dict(dictionary):
try:
return GameVersion(Version.from_dict(dictionary['engine']),
Mod.from_dict(dictionary['main_mod']),
engine = dictionary['engine'] if isinstance(dictionary['engine'], Version)\
else Version.from_dict(dictionary['engine'])
main_mod = dictionary['main_mod'] if isinstance(dictionary['main_mod'], Mod)\
else Mod.from_dict(dictionary['main_mod'])
return GameVersion(engine,
main_mod,
dictionary.get('mods'),
dictionary.get('map'))
except (KeyError, ValueError) as e:
Expand Down
2 changes: 1 addition & 1 deletion src/fa/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def getGameFolderFA():
settings.beginGroup("ForgedAlliance")
gameFolderFA = unicode(settings.value("app/path"))
settings.endGroup()
return gameFolderFA
return fixFolderPathFA(gameFolderFA)

def setGameFolderFA(newGameFolderFA):
logger.info("Setting game path to: %s" % newGameFolderFA)
Expand Down
2 changes: 1 addition & 1 deletion tests/fa/test_init_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def test_default_init_file():

def test_path_gets_amended():
f = InitFile()
f.mount('c:\\\\some-directory\\\\', '/')
f.mount('c:\\some-directory\\', '/')
print f.to_lua()
lua.execute(f.to_lua())
path = []
Expand Down
7 changes: 5 additions & 2 deletions tests/fa/test_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@ def test_hotfixFA():

# create fake game
gamedata = os.path.join(root, 'gamedata')
os.makedirs(gamedata)
try:
os.makedirs(gamedata)
except os.error:
pass
lua = os.path.join(gamedata, 'lua.scd')
open(lua, 'a').close()

# positive test
subfolders = ['\\bin', \
subfolders = ['\\bin',
'\\bin\\SupremeCommander.exe']
for sub in subfolders:
path.setGameFolderFA(folderFA + sub)
Expand Down
23 changes: 3 additions & 20 deletions tests/fa/test_play.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

from flexmock import flexmock

from config import Settings

process_mock = flexmock()
settings_mock = flexmock()

Expand All @@ -14,26 +16,6 @@
fa.play.Settings = settings_mock


def test_launches_process_with_given_arguments(game_version, tmpdir):
game_info = {
'uid': 0,
'recorder': 'Sheeo',
'version': game_version
}
expected_args = [('some-arg', 'test')]

def validate_args(game_info, args, detach, init_file):
for k, v in expected_args:
assert k in dict(args).keys()
assert dict(args)[k] == v
return True

settings_mock.should_receive('get').with_args('WRITE_GAME_LOG', 'FA').and_return(False)
settings_mock.should_receive('get').with_args('BIN', 'FA').and_return(str(tmpdir))
process_mock.should_receive('run').replace_with(validate_args)
assert fa.run(game_info, 0, expected_args)


def test_constructs_and_uses_init_file_from_game_version(game_version, tmpdir):
game_info = {
'uid': 0,
Expand All @@ -42,6 +24,7 @@ def test_constructs_and_uses_init_file_from_game_version(game_version, tmpdir):
}
settings_mock.should_receive('get').with_args('WRITE_GAME_LOG', 'FA').and_return(False)
settings_mock.should_receive('get').with_args('BIN', 'FA').and_return(str(tmpdir))
settings_mock.should_receive('get').with_args('MODS_PATH', 'FA').and_return(str(tmpdir))

def validate_args(game_info, args, detach, init_file):
assert dict(args)['init'] == str(tmpdir.join('init_%s.lua' % game_version.main_mod.name))
Expand Down

1 comment on commit 62c9e24

@Sheeo
Copy link
Member Author

@Sheeo Sheeo commented on 62c9e24 Dec 3, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well. This was a reminder of why we use unit testing :) 👍

Please sign in to comment.