diff options
| author | Mike Frysinger <vapier@google.com> | 2019-11-15 01:19:03 -0500 |
|---|---|---|
| committer | Mike Frysinger <vapier@google.com> | 2019-11-16 23:55:30 +0000 |
| commit | 70c54dc2550084ed022a2f134065a011f37f30aa (patch) | |
| tree | 6086cb67a1b1f928892b4d47d1b77a069b5ae31f /tests/test_editor.py | |
| parent | 6da17751ca4e3b90834ca763f448ddc39b32651b (diff) | |
| download | git-repo-70c54dc2550084ed022a2f134065a011f37f30aa.tar.gz | |
upload/editor: fix bytes/string confusion
The upload module tries to turn the strings into bytes before passing
to EditString, but it combines bytes & strings causing an error. The
return value might be bytes or string, but the caller only expects a
string. Lets simplify this by sticking to strings everywhere and have
EditString take care of converting to/from bytes when reading/writing
the underlying files. This also avoids possible locale confusion when
reading the file by forcing UTF-8 everywhere.
Bug: https://crbug.com/gerrit/11929
Change-Id: I07b146170c5e8b5b0500a2c79e4213cd12140a96
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/245621
Reviewed-by: David Pursehouse <dpursehouse@collab.net>
Tested-by: Mike Frysinger <vapier@google.com>
Diffstat (limited to 'tests/test_editor.py')
| -rw-r--r-- | tests/test_editor.py | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/tests/test_editor.py b/tests/test_editor.py new file mode 100644 index 00000000..fbcfcdbd --- /dev/null +++ b/tests/test_editor.py | |||
| @@ -0,0 +1,60 @@ | |||
| 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')) | ||
