File: test_pyface_utils.py

package info (click to toggle)
mayavi2 4.8.3-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 21,892 kB
  • sloc: python: 49,447; javascript: 32,885; makefile: 129; fortran: 60
file content (38 lines) | stat: -rw-r--r-- 1,176 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import unittest
from unittest.mock import Mock, patch
from traits.etsconfig.api import ETSConfig

from pyface.api import FileDialog, NO, OK


class TestPopupSave(unittest.TestCase):

    def _make_mock_file_dialog(self, return_value):
        m = Mock(spec=FileDialog)
        m.open.return_value = return_value
        m.path = 'mock'
        return m

    @unittest.skipIf(ETSConfig.toolkit == 'null',
                     'Test meaningless with null toolkit.')
    def test_popup_save_with_user_ok(self):
        with patch('pyface.api.FileDialog') as fd:
            fd.return_value = self._make_mock_file_dialog(OK)
            from tvtk.pyface.utils import popup_save
            x = popup_save()

        self.assertEqual(x, 'mock')

    @unittest.skipIf(ETSConfig.toolkit == 'null',
                     'Test meaningless with null toolkit.')
    def test_popup_save_with_user_not_ok(self):
        with patch('pyface.api.FileDialog') as fd:
            fd.return_value = self._make_mock_file_dialog(NO)
            from tvtk.pyface.utils import popup_save
            x = popup_save()

        self.assertEqual(x, '')


if __name__ == '__main__':
    unittest.main()