test_editor.py 1.5 KB

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