Modify ↓
Ticket #236 (closed defect: invalid)
PyYAML strips \n in the end of documents
| Reported by: | Matěj Cepl <mcepl@…> | Owned by: | xi |
|---|---|---|---|
| Priority: | normal | Component: | pyyaml |
| Severity: | normal | Keywords: | |
| Cc: |
Description
When running the attached script the test fails:
mitmanek:yamlish (master) $ python failing_test.py
F
======================================================================
FAIL: test_file_output (__main__.TestOuptut)
----------------------------------------------------------------------
Traceback (most recent call last):
File "failing_test.py", line 52, in test_file_output
""" % (self._expected, got))
AssertionError: Result matches
expected = {'bill-to': {'address': {'lines': '458 Walkman Dr. Suite #292 '}}, 'comments': 'Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338'}
observed = {'bill-to': {'address': {'lines': '458 Walkman Dr.\nSuite #292\n'}}, 'comments': 'Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338\n'}
----------------------------------------------------------------------
Ran 1 test in 0.006s
FAILED (failures=1)
mitmanek:yamlish (master) $
Attachments
Change History
Changed 15 months ago by Matěj Cepl <mcepl@…>
-
attachment
failing_test.py
added
comment:1 Changed 15 months ago by Matěj Cepl <mcepl@…>
- Summary changed from PyYAML doesn't round-trip \n to PyYAML strips \n in the end of documents
New version of the test case show cleanly that only \n in the end of document are killed (why? What's different about them?). Running the test case I get:
mitmanek:yamlish (master) $ unit2 -v failing_test
test_file_output (failing_test.TestOuptut) ... FAIL
======================================================================
FAIL: test_file_output (failing_test.TestOuptut)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/matej/archiv/2012/RedHat/projekty/yamlish/failing_test.py", line 48, in test_file_output
self.assertEqual(self._expected, got, "Result matches")
AssertionError: {'bill-to': {'address': {'lines': '458 Walkman Dr.\nSuite #292\n'}}, 'comments': [truncated]... != {'bill-to': {'address': {'lines': '458 Walkman Dr.\nSuite #292\n'}}, 'comments': [truncated]...
{'bill-to': {'address': {'lines': '458 Walkman Dr.\nSuite #292\n'}},
- 'comments': 'Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338'}
+ 'comments': 'Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338\n'}
? ++
: Result matches
----------------------------------------------------------------------
Ran 1 test in 0.009s
FAILED (failures=1)
mitmanek:yamlish (master) $
comment:2 Changed 15 months ago by xi
- Status changed from new to closed
- Resolution set to invalid
PyYAML interpretation is correct: a single newline character in a double-quoted scalar is converted to a space; any trailing newline characters at the end of an unquoted scalar are ignored.
You are sure you understand how \n works in Python strings?
Note: See
TracTickets for help on using
tickets.

simple test case