|
| 1 | +# -*- coding: UTF-8 -*- |
1 | 2 | from __future__ import absolute_import |
2 | 3 | from __future__ import unicode_literals |
3 | 4 |
|
@@ -34,9 +35,14 @@ def foo_staged(tmpdir_factory): |
34 | 35 | yield auto_namedtuple(path=path, foo_filename=foo_filename) |
35 | 36 |
|
36 | 37 |
|
37 | | -def _test_foo_state(path, foo_contents=FOO_CONTENTS, status='A'): |
| 38 | +def _test_foo_state( |
| 39 | + path, |
| 40 | + foo_contents=FOO_CONTENTS, |
| 41 | + status='A', |
| 42 | + encoding='UTF-8', |
| 43 | +): |
38 | 44 | assert os.path.exists(path.foo_filename) |
39 | | - assert io.open(path.foo_filename, encoding='utf-8').read() == foo_contents |
| 45 | + assert io.open(path.foo_filename, encoding=encoding).read() == foo_contents |
40 | 46 | actual_status = get_short_git_status()['foo'] |
41 | 47 | assert status == actual_status |
42 | 48 |
|
@@ -246,10 +252,22 @@ def test_diff_returns_1_no_diff_though(fake_logging_handler, foo_staged): |
246 | 252 |
|
247 | 253 | def test_stage_utf8_changes(foo_staged, cmd_runner): |
248 | 254 | contents = '\u2603' |
249 | | - with io.open('foo', 'w', encoding='utf-8') as foo_file: |
| 255 | + with io.open('foo', 'w', encoding='UTF-8') as foo_file: |
250 | 256 | foo_file.write(contents) |
251 | 257 |
|
252 | 258 | _test_foo_state(foo_staged, contents, 'AM') |
253 | 259 | with staged_files_only(cmd_runner): |
254 | 260 | _test_foo_state(foo_staged) |
255 | 261 | _test_foo_state(foo_staged, contents, 'AM') |
| 262 | + |
| 263 | + |
| 264 | +def test_stage_non_utf8_changes(foo_staged, cmd_runner): |
| 265 | + contents = 'ú' |
| 266 | + # Produce a latin-1 diff |
| 267 | + with io.open('foo', 'w', encoding='latin-1') as foo_file: |
| 268 | + foo_file.write(contents) |
| 269 | + |
| 270 | + _test_foo_state(foo_staged, contents, 'AM', encoding='latin-1') |
| 271 | + with staged_files_only(cmd_runner): |
| 272 | + _test_foo_state(foo_staged) |
| 273 | + _test_foo_state(foo_staged, contents, 'AM', encoding='latin-1') |
0 commit comments