blob: 8f5d160e206917bb7d7171163bde1d9a14e68b65 [file] [log] [blame]
Mike Frysinger70c54dc2019-11-15 01:19:03 -05001# Copyright (C) 2019 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15"""Unittests for the editor.py module."""
16
Mike Frysinger70c54dc2019-11-15 01:19:03 -050017import unittest
18
19from editor import Editor
20
21
22class EditorTestCase(unittest.TestCase):
Gavin Makea2e3302023-03-11 06:46:20 +000023 """Take care of resetting Editor state across tests."""
Mike Frysinger70c54dc2019-11-15 01:19:03 -050024
Gavin Makea2e3302023-03-11 06:46:20 +000025 def setUp(self):
26 self.setEditor(None)
Mike Frysinger70c54dc2019-11-15 01:19:03 -050027
Gavin Makea2e3302023-03-11 06:46:20 +000028 def tearDown(self):
29 self.setEditor(None)
Mike Frysinger70c54dc2019-11-15 01:19:03 -050030
Gavin Makea2e3302023-03-11 06:46:20 +000031 @staticmethod
32 def setEditor(editor):
33 Editor._editor = editor
Mike Frysinger70c54dc2019-11-15 01:19:03 -050034
35
36class GetEditor(EditorTestCase):
Gavin Makea2e3302023-03-11 06:46:20 +000037 """Check GetEditor behavior."""
Mike Frysinger70c54dc2019-11-15 01:19:03 -050038
Gavin Makea2e3302023-03-11 06:46:20 +000039 def test_basic(self):
40 """Basic checking of _GetEditor."""
41 self.setEditor(":")
42 self.assertEqual(":", Editor._GetEditor())
Mike Frysinger70c54dc2019-11-15 01:19:03 -050043
44
45class EditString(EditorTestCase):
Gavin Makea2e3302023-03-11 06:46:20 +000046 """Check EditString behavior."""
Mike Frysinger70c54dc2019-11-15 01:19:03 -050047
Gavin Makea2e3302023-03-11 06:46:20 +000048 def test_no_editor(self):
49 """Check behavior when no editor is available."""
50 self.setEditor(":")
51 self.assertEqual("foo", Editor.EditString("foo"))
Mike Frysinger70c54dc2019-11-15 01:19:03 -050052
Gavin Makea2e3302023-03-11 06:46:20 +000053 def test_cat_editor(self):
54 """Check behavior when editor is `cat`."""
55 self.setEditor("cat")
56 self.assertEqual("foo", Editor.EditString("foo"))