Skip to content

Commit

Permalink
Fixed missing "self." in ui.launcher_update_check
Browse files Browse the repository at this point in the history
pep8
Finished unit tests. coverage comes to ~97%(excluding main.py)
  • Loading branch information
MosesofEgypt committed Jun 19, 2017
1 parent 162936b commit e8da1d7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/ui.py
Expand Up @@ -247,7 +247,7 @@ async def launcher_update_check(self):
self.launch_game_btn.setText(_('Updating Launcher'))
self.launch_game_btn.show()
self.progress_bar.show()
await download_tracker.run_async()
await self.download_tracker.run_async()
if remote_launcher_hash != sha256_hash(temp_file):
logging.error('Downloaded launcher does not match one'
' described by remote hash file.')
Expand Down
5 changes: 3 additions & 2 deletions test/test_config.py
Expand Up @@ -126,11 +126,12 @@ def test_translations_cannot_be_installed_twice(self):

def test_config_can_load_config(self):
config.CONFIG = None
config.setup_logger()
config.setup_directories()
config.setup_logger()
config.setup_directories()
config.install_translations()

resource_config = os.path.join(config.RESOURCE_DIR, config.CONFIG_NAME)

def resource_exists_mock(path):
return path == resource_config

Expand Down
39 changes: 29 additions & 10 deletions test/test_ui.py
Expand Up @@ -73,6 +73,11 @@


def fix_sys_argv_and_frozen(has_argv, has_frozen, argv, frozen):
'''
Deletes sys.argv and sys.frozen and replaces them with the provided
argv if has_argv is True and frozen if has_frozen is True.
Used to restore sys.argv and sys.frozen when testing launcher_update_check
'''
try:
del sys.argv
except AttributeError:
Expand Down Expand Up @@ -670,21 +675,25 @@ def test_main_window_launcher_update_can_succeed(self):
executable = getattr(sys, 'executable')
sys.executable = 'test_exec.bin'
launcher_hash = 'qwerty'
remote_hash = 'qwerty'
# TODO: Finish this test
return
remote_hash = 'asdf'

with mock.patch('ui.sha256_hash', return_value=launcher_hash) as m1,\
mock.patch('requests.get', return_value=response) as m2,\
async_patch('download.DownloadTracker.run_async', asdf) as m3,\
mock.patch('os.path.exists', asdf) as m4,\
mock.patch('os.remove', asdf) as m5,\
mock.patch('os.rename', asdf) as m6,\
mock.patch('os.chmod', asdf) as m7,\
mock.patch('subprocess.Popen', asdf) as m8,\
mock.patch('sys.exit', asdf) as m9:
async_patch('download.DownloadTracker.run_async') as m3,\
mock.patch('os.path.getsize', return_value=0) as m4,\
mock.patch('os.path.exists', return_value=True) as m5,\
mock.patch('os.remove') as m6,\
mock.patch('os.rename') as m7,\
mock.patch('os.chmod') as m8,\
mock.patch('subprocess.Popen') as m9,\
mock.patch('sys.exit') as m10:
response._text = remote_hash
try:
has_argv = hasattr(sys, 'argv')
has_frozen = hasattr(sys, 'frozen')
argv = getattr(sys, 'argv', None)
frozen = getattr(sys, 'frozen', None)
sys.argv, sys.frozen = [], True
self.run_async(main_window.launcher_update_check)
exception = None
except Exception as e:
Expand All @@ -695,6 +704,16 @@ def test_main_window_launcher_update_can_succeed(self):
if exception is not None:
raise exception

old_file = sys.executable + '.old'

m4.assert_called_once_with(sys.executable)
m5.assert_called_once_with(old_file)
m6.assert_called_once_with(old_file)
self.assertEqual(m7.call_count, 2)
m8.assert_called_once_with(sys.executable, 0o750)
m9.assert_called_once_with([sys.executable])
m10.assert_called_once_with(0)

if has_exec:
sys.executable = executable

Expand Down

0 comments on commit e8da1d7

Please sign in to comment.