Skip to content
Snippets Groups Projects
Commit 5148fd47 authored by Paul McCarthy's avatar Paul McCarthy :mountain_bicyclist:
Browse files

Made some platform unit tests a bit more useful

parent ef247ed0
No related branches found
No related tags found
No related merge requests found
...@@ -8,15 +8,18 @@ ...@@ -8,15 +8,18 @@
import os import os
import os.path as op import os.path as op
import sys
import shutil import shutil
import tempfile import tempfile
import mock
import fsl.utils.platform as fslplatform import fsl.utils.platform as fslplatform
def test_atts(): def test_atts():
p = fslplatform.platform p = fslplatform.platform
p.os p.os
p.frozen p.frozen
...@@ -32,11 +35,11 @@ def test_atts(): ...@@ -32,11 +35,11 @@ def test_atts():
p.glIsSoftwareRenderer p.glIsSoftwareRenderer
def test_gui(): def test_haveGui():
import wx import wx
p = fslplatform.platform p = fslplatform.Platform()
app = wx.App() app = wx.App()
frame = wx.Frame(None) frame = wx.Frame(None)
passed = [False] passed = [False]
...@@ -45,10 +48,7 @@ def test_gui(): ...@@ -45,10 +48,7 @@ def test_gui():
def runtest(): def runtest():
try: try:
assert p.haveGui
p.haveGui
p.wxPlatform
p.wxFlavour
passed[0] = True passed[0] = True
finally: finally:
frame.Destroy() frame.Destroy()
...@@ -61,14 +61,94 @@ def test_gui(): ...@@ -61,14 +61,94 @@ def test_gui():
assert passed[0] assert passed[0]
def test_wxatts():
with mock.patch.dict('sys.modules', wx=None):
p = fslplatform.Platform()
assert not p.canHaveGui
assert not p.haveGui
assert p.wxFlavour == fslplatform.WX_UNKNOWN
assert p.wxPlatform == fslplatform.WX_UNKNOWN
with mock.patch('wx.App.IsDisplayAvailable', return_value=False):
p = fslplatform.Platform()
assert not p.canHaveGui
assert not p.haveGui
assert p.wxFlavour == fslplatform.WX_UNKNOWN
assert p.wxPlatform == fslplatform.WX_UNKNOWN
with mock.patch('wx.App.IsDisplayAvailable', return_value=True), \
mock.patch('wx.PlatformInfo', ('gtk', 'phoenix')):
p = fslplatform.Platform()
assert p.canHaveGui
assert not p.haveGui
assert p.wxFlavour == fslplatform.WX_PHOENIX
assert p.wxPlatform == fslplatform.WX_GTK
# (wx.PlatformInfo, expected platform, expected flavour)
platflavtests = [
(('__WXMAC__',
'wxMac',
'unicode',
'unicode-wchar',
'wxOSX',
'wxOSX-cocoa',
'wx-assertions-on',
'phoenix',
'wxWidgets 3.0.4'),
fslplatform.WX_MAC_COCOA,
fslplatform.WX_PHOENIX),
(('__WXMAC__',
'wxMac',
'unicode',
'wxOSX',
'wxOSX-cocoa',
'wx-assertions-on',
'SWIG-1.3.29'),
fslplatform.WX_MAC_COCOA,
fslplatform.WX_PYTHON),
(('__WXGTK__',
'wxGTK',
'unicode',
'unicode-wchar',
'gtk2',
'wx-assertions-on',
'phoenix',
'wxWidgets 3.0.4'),
fslplatform.WX_GTK,
fslplatform.WX_PHOENIX),
(('__WXGTK__',
'wxGTK',
'unicode',
'gtk2',
'wx-assertions-on',
'SWIG-1.3.29'),
fslplatform.WX_GTK,
fslplatform.WX_PYTHON)]
for platinfo, expplatform, expflavour in platflavtests:
with mock.patch('wx.PlatformInfo', platinfo):
p = fslplatform.Platform()
assert p.wxFlavour == expflavour
assert p.wxPlatform == expplatform
def test_gl(): def test_gl():
p = fslplatform.platform p = fslplatform.Platform()
p.glVersion = '2.1' p.glVersion = '2.1'
p.glRenderer = 'Fake renderer' p.glRenderer = 'Fake renderer'
assert p.glVersion == '2.1'
assert p.glRenderer == 'Fake renderer'
def test_fsldir(): def test_fsldir():
# We have to make a dummy directory that looks like FSL # We have to make a dummy directory that looks like FSL
...@@ -84,7 +164,7 @@ def test_fsldir(): ...@@ -84,7 +164,7 @@ def test_fsldir():
makeFSL() makeFSL()
p = fslplatform.platform p = fslplatform.Platform()
newFSLDir = [None] newFSLDir = [None]
def fsldirChanged(p, t, val): def fsldirChanged(p, t, val):
...@@ -104,7 +184,29 @@ def test_fsldir(): ...@@ -104,7 +184,29 @@ def test_fsldir():
finally: finally:
shutil.rmtree(testdir) shutil.rmtree(testdir)
def test_detect_ssh():
sshVars = ['SSH_CLIENT', 'SSH_TTY']
vncVars = ['VNCDESKTOP', 'X2GO_SESSION', 'NXSESSIONID']
for sv in sshVars:
with mock.patch.dict('os.environ', **{ sv : '1'}):
p = fslplatform.Platform()
assert p.inSSHSession
for vv in vncVars:
with mock.patch.dict('os.environ', **{ vv : '1'}):
p = fslplatform.Platform()
assert p.inVNCSession
with mock.patch('os.environ', {}):
p = fslplatform.Platform()
assert not p.inSSHSession
assert not p.inVNCSession
def test_IsWidgetAlive(): def test_IsWidgetAlive():
import wx import wx
...@@ -122,7 +224,7 @@ def test_IsWidgetAlive(): ...@@ -122,7 +224,7 @@ def test_IsWidgetAlive():
passed[0] = fslplatform.isWidgetAlive(btn) passed[0] = fslplatform.isWidgetAlive(btn)
btn.Destroy() btn.Destroy()
passed[0] = passed[0] and (not fslplatform.isWidgetAlive(btn)) passed[0] = passed[0] and (not fslplatform.isWidgetAlive(btn))
finally: finally:
frame.Destroy() frame.Destroy()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment