Mike Frysinger | 70c54dc | 2019-11-15 01:19:03 -0500 | [diff] [blame] | 1 | # 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 Frysinger | 70c54dc | 2019-11-15 01:19:03 -0500 | [diff] [blame] | 17 | import unittest |
| 18 | |
| 19 | from editor import Editor |
| 20 | |
| 21 | |
| 22 | class EditorTestCase(unittest.TestCase): |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 23 | """Take care of resetting Editor state across tests.""" |
Mike Frysinger | 70c54dc | 2019-11-15 01:19:03 -0500 | [diff] [blame] | 24 | |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 25 | def setUp(self): |
| 26 | self.setEditor(None) |
Mike Frysinger | 70c54dc | 2019-11-15 01:19:03 -0500 | [diff] [blame] | 27 | |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 28 | def tearDown(self): |
| 29 | self.setEditor(None) |
Mike Frysinger | 70c54dc | 2019-11-15 01:19:03 -0500 | [diff] [blame] | 30 | |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 31 | @staticmethod |
| 32 | def setEditor(editor): |
| 33 | Editor._editor = editor |
Mike Frysinger | 70c54dc | 2019-11-15 01:19:03 -0500 | [diff] [blame] | 34 | |
| 35 | |
| 36 | class GetEditor(EditorTestCase): |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 37 | """Check GetEditor behavior.""" |
Mike Frysinger | 70c54dc | 2019-11-15 01:19:03 -0500 | [diff] [blame] | 38 | |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 39 | def test_basic(self): |
| 40 | """Basic checking of _GetEditor.""" |
| 41 | self.setEditor(":") |
| 42 | self.assertEqual(":", Editor._GetEditor()) |
Mike Frysinger | 70c54dc | 2019-11-15 01:19:03 -0500 | [diff] [blame] | 43 | |
| 44 | |
| 45 | class EditString(EditorTestCase): |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 46 | """Check EditString behavior.""" |
Mike Frysinger | 70c54dc | 2019-11-15 01:19:03 -0500 | [diff] [blame] | 47 | |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 48 | def test_no_editor(self): |
| 49 | """Check behavior when no editor is available.""" |
| 50 | self.setEditor(":") |
| 51 | self.assertEqual("foo", Editor.EditString("foo")) |
Mike Frysinger | 70c54dc | 2019-11-15 01:19:03 -0500 | [diff] [blame] | 52 | |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 53 | def test_cat_editor(self): |
| 54 | """Check behavior when editor is `cat`.""" |
| 55 | self.setEditor("cat") |
| 56 | self.assertEqual("foo", Editor.EditString("foo")) |