test_editor.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. """Unittests for the editor.py module."""
  17. from __future__ import print_function
  18. import unittest
  19. from editor import Editor
  20. class EditorTestCase(unittest.TestCase):
  21. """Take care of resetting Editor state across tests."""
  22. def setUp(self):
  23. self.setEditor(None)
  24. def tearDown(self):
  25. self.setEditor(None)
  26. @staticmethod
  27. def setEditor(editor):
  28. Editor._editor = editor
  29. class GetEditor(EditorTestCase):
  30. """Check GetEditor behavior."""
  31. def test_basic(self):
  32. """Basic checking of _GetEditor."""
  33. self.setEditor(':')
  34. self.assertEqual(':', Editor._GetEditor())
  35. class EditString(EditorTestCase):
  36. """Check EditString behavior."""
  37. def test_no_editor(self):
  38. """Check behavior when no editor is available."""
  39. self.setEditor(':')
  40. self.assertEqual('foo', Editor.EditString('foo'))
  41. def test_cat_editor(self):
  42. """Check behavior when editor is `cat`."""
  43. self.setEditor('cat')
  44. self.assertEqual('foo', Editor.EditString('foo'))