[tests/theme] Fix WAL mocked tests

Until now, the WAL tests depended on the pyWAL cache file being actually
present on the system.
This commit is contained in:
tobi-wan-kenobi 2020-04-13 13:47:50 +02:00
parent dc5bfd1fc6
commit 580bb20a9f

View file

@ -85,21 +85,26 @@ class theme(unittest.TestCase):
def test_wal_colors(self):
with unittest.mock.patch('core.theme.io') as io:
io.open.return_value.__enter__.return_value.read.return_value='''
{ "colors": { "red": "#ff0000" } }
'''
with unittest.mock.patch('core.theme.os') as os:
os.path.isfile.return_value = True
io.open.return_value = unittest.mock.MagicMock()
io.open.return_value.__enter__.return_value.read.return_value='''
{ "colors": { "red": "#ff0000" } }
'''
theme = core.theme.Theme(raw_data=self.walTheme)
self.assertEqual({'red': '#ff0000'}, theme.keywords())
theme = core.theme.Theme(raw_data=self.walTheme)
self.assertEqual({'red': '#ff0000'}, theme.keywords())
def test_wal_special(self):
with unittest.mock.patch('core.theme.io') as io:
io.open.return_value.__enter__.return_value.read.return_value='''
{ "special": { "background": "#ff0000" } }
'''
with unittest.mock.patch('core.theme.os') as os:
os.path.isfile.return_value = True
io.open.return_value.__enter__.return_value.read.return_value='''
{ "special": { "background": "#ff0000" } }
'''
theme = core.theme.Theme(raw_data=self.walTheme)
self.assertEqual({'background': '#ff0000'}, theme.keywords())
theme = core.theme.Theme(raw_data=self.walTheme)
self.assertEqual({'background': '#ff0000'}, theme.keywords())
def test_cycle_value(self):
widget = core.widget.Widget()