Mike Frysinger | 70c54dc | 2019-11-15 01:19:03 -0500 | [diff] [blame] | 1 | # -*- coding:utf-8 -*- |
| 2 | # |
| 3 | # Copyright (C) 2019 The Android Open Source Project |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
| 17 | """Unittests for the editor.py module.""" |
| 18 | |
| 19 | from __future__ import print_function |
| 20 | |
| 21 | import unittest |
| 22 | |
| 23 | from editor import Editor |
| 24 | |
| 25 | |
| 26 | class EditorTestCase(unittest.TestCase): |
| 27 | """Take care of resetting Editor state across tests.""" |
| 28 | |
| 29 | def setUp(self): |
| 30 | self.setEditor(None) |
| 31 | |
| 32 | def tearDown(self): |
| 33 | self.setEditor(None) |
| 34 | |
| 35 | @staticmethod |
| 36 | def setEditor(editor): |
| 37 | Editor._editor = editor |
| 38 | |
| 39 | |
| 40 | class GetEditor(EditorTestCase): |
| 41 | """Check GetEditor behavior.""" |
| 42 | |
| 43 | def test_basic(self): |
| 44 | """Basic checking of _GetEditor.""" |
| 45 | self.setEditor(':') |
| 46 | self.assertEqual(':', Editor._GetEditor()) |
| 47 | |
| 48 | |
| 49 | class EditString(EditorTestCase): |
| 50 | """Check EditString behavior.""" |
| 51 | |
| 52 | def test_no_editor(self): |
| 53 | """Check behavior when no editor is available.""" |
| 54 | self.setEditor(':') |
| 55 | self.assertEqual('foo', Editor.EditString('foo')) |
| 56 | |
| 57 | def test_cat_editor(self): |
| 58 | """Check behavior when editor is `cat`.""" |
| 59 | self.setEditor('cat') |
| 60 | self.assertEqual('foo', Editor.EditString('foo')) |