blob: fbcfcdbda397b650406f36d6d8c841218a4b72c0 [file] [log] [blame]
Mike Frysinger70c54dc2019-11-15 01:19:03 -05001# -*- 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
19from __future__ import print_function
20
21import unittest
22
23from editor import Editor
24
25
26class 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
40class 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
49class 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'))