From 1d0fdbaa138a8a78379bff504bb0c3acab399809 Mon Sep 17 00:00:00 2001 From: Aaron Robson Date: Sun, 12 Jan 2020 20:00:21 +0000 Subject: [PATCH] fix #429: include a trailing newline in the JSON cassette format It is a common convention for text files (esp. in Linux) to end with a newline. --- tests/integration/test_config.py | 4 +++- vcr/serializers/jsonserializer.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/integration/test_config.py b/tests/integration/test_config.py index 30c9089..4c8c595 100644 --- a/tests/integration/test_config.py +++ b/tests/integration/test_config.py @@ -13,7 +13,9 @@ def test_set_serializer_default_config(tmpdir, httpbin): urlopen(httpbin.url + "/get") with open(str(tmpdir.join("test.json"))) as f: - assert json.loads(f.read()) + file_content = f.read() + assert file_content.endswith("\n") + assert json.loads(file_content) def test_default_set_cassette_library_dir(tmpdir, httpbin): diff --git a/vcr/serializers/jsonserializer.py b/vcr/serializers/jsonserializer.py index e5ff85a..5ffef3e 100644 --- a/vcr/serializers/jsonserializer.py +++ b/vcr/serializers/jsonserializer.py @@ -16,7 +16,7 @@ def serialize(cassette_dict): ) try: - return json.dumps(cassette_dict, indent=4) + return json.dumps(cassette_dict, indent=4) + "\n" except UnicodeDecodeError as original: # py2 raise UnicodeDecodeError( original.encoding,