codeplain 0.3.13.dev35__py3-none-any.whl → 0.3.13.dev37__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {codeplain-0.3.13.dev35.dist-info → codeplain-0.3.13.dev37.dist-info}/METADATA +1 -1
- {codeplain-0.3.13.dev35.dist-info → codeplain-0.3.13.dev37.dist-info}/RECORD +7 -7
- file_utils.py +17 -1
- tests/test_file_utils.py +86 -4
- {codeplain-0.3.13.dev35.dist-info → codeplain-0.3.13.dev37.dist-info}/WHEEL +0 -0
- {codeplain-0.3.13.dev35.dist-info → codeplain-0.3.13.dev37.dist-info}/entry_points.txt +0 -0
- {codeplain-0.3.13.dev35.dist-info → codeplain-0.3.13.dev37.dist-info}/licenses/LICENSE +0 -0
|
@@ -4,7 +4,7 @@ concept_utils.py,sha256=TpyiQ4DfMtO231j-lPj65i0suRTPr8t9j3QNf9KiM4A,8080
|
|
|
4
4
|
conformance_fix_journal.py,sha256=7wL3UOc3BWaUo5MCmiFbb3kIwOQ6iEpdQSyEmedo8Vk,9488
|
|
5
5
|
diff_utils.py,sha256=AjiQlqo5pRos_8hVXZo5yBurl5BzSrTMGrQv4dCtRCg,1198
|
|
6
6
|
event_bus.py,sha256=g5XLwRfjrvTIcB6urjREuCJzZj5TA93hy8lKXLGXuCE,650
|
|
7
|
-
file_utils.py,sha256=
|
|
7
|
+
file_utils.py,sha256=uSgNzrQ3rXYnTEwdyFrsOvwvnEZ2bGfaBDOQpEDV0g8,12955
|
|
8
8
|
git_preflight.py,sha256=vB2A8GyYz_iWr8jOE4POFLBHr3qihmedWuidspGdsrw,1509
|
|
9
9
|
git_utils.py,sha256=gCUA6_9zg19f6k_0aVcRnIVlAJSBD0Vt6takx-0pKME,16547
|
|
10
10
|
memory_management.py,sha256=CwIOQqF7Xo1sNfvP69zQRK_CpjinQD9dbolhRPl6lTk,2446
|
|
@@ -79,7 +79,7 @@ tests/test_conformance_fix_journal.py,sha256=olTeAuxXgFwQ8LSQyt0FqtBy9_XY_gK-Ei_
|
|
|
79
79
|
tests/test_console_log_styles.py,sha256=sxlhynMAP-kmqhBn1-pKvZXdCnlKSyCGJqwYKrh6sQ0,6468
|
|
80
80
|
tests/test_distill_conformance_test_memory.py,sha256=Tftw9l-gLVwIU6QttY03h2VedvuFxpIsCmZIzvWfxMA,5481
|
|
81
81
|
tests/test_dry_run_link_validation.py,sha256=ivvYXQPqUkQ8glbFyUrdCninCxF2mg-rAsDcfjcB7MM,2140
|
|
82
|
-
tests/test_file_utils.py,sha256=
|
|
82
|
+
tests/test_file_utils.py,sha256=a8OOuLdEyduaoOw7pFy5XtAtXIVUJkgdzRoFNHBezMg,7437
|
|
83
83
|
tests/test_fix_unit_tests_action.py,sha256=0xY94BFbYa528LBXmO7_gfVNbQEqdzXsDHPjQV5qfy0,11410
|
|
84
84
|
tests/test_fix_unit_tests_conformance_context.py,sha256=G6-_YMhN5BY1sJ7cAx3BDnf_McgFcRpyP0iP6mwJ1eA,13154
|
|
85
85
|
tests/test_folder_path_resolution.py,sha256=K9v684xkPE0HOAsovg8uDixpZmaIk7ho-Wd3rTjKLF0,6560
|
|
@@ -121,8 +121,8 @@ tui/spinner.py,sha256=Ro6Gd9Przf-whuHqPRY6HwI0T57yJjyNPbhDbigZKZE,2471
|
|
|
121
121
|
tui/state_handlers.py,sha256=zbUS_D9eU8qIwVpaxPEp9zL9bpg8gXsWNoUaqg9TLrQ,16664
|
|
122
122
|
tui/styles.css,sha256=kiC7Og_2G1E7owoiZgV95-3_dSeQnsNj3qzaY04xkDg,6727
|
|
123
123
|
tui/widget_helpers.py,sha256=jitm2WHiKj-NVFL-hULxWzckPreRbUTl9OIZLN31-ek,6997
|
|
124
|
-
codeplain-0.3.13.
|
|
125
|
-
codeplain-0.3.13.
|
|
126
|
-
codeplain-0.3.13.
|
|
127
|
-
codeplain-0.3.13.
|
|
128
|
-
codeplain-0.3.13.
|
|
124
|
+
codeplain-0.3.13.dev37.dist-info/METADATA,sha256=wvWxnf5GyZq2gnyX5U-613pqapbCu2xo5MYRCK9HRIA,7257
|
|
125
|
+
codeplain-0.3.13.dev37.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
|
|
126
|
+
codeplain-0.3.13.dev37.dist-info/entry_points.txt,sha256=oDZkBqu9WhtZApb_K6ia8-fn9aojwmAsgnKELceX5T4,46
|
|
127
|
+
codeplain-0.3.13.dev37.dist-info/licenses/LICENSE,sha256=pCeKgQ1mXE5OmNUuKOfOZh1T1vqkeCUxghE7N8qgnzc,11345
|
|
128
|
+
codeplain-0.3.13.dev37.dist-info/RECORD,,
|
file_utils.py
CHANGED
|
@@ -142,7 +142,21 @@ def get_existing_files_content(build_folder, existing_files):
|
|
|
142
142
|
return existing_files_content
|
|
143
143
|
|
|
144
144
|
|
|
145
|
+
def ensure_final_newline(content: str) -> str:
|
|
146
|
+
"""Ends non-empty text with a newline, as linters expect (e.g. RuboCop, ESLint eol-last, Ruff W292)."""
|
|
147
|
+
if content and not content.endswith("\n"):
|
|
148
|
+
return content + "\n"
|
|
149
|
+
return content
|
|
150
|
+
|
|
151
|
+
|
|
145
152
|
def store_response_files(target_folder, response_files, existing_files):
|
|
153
|
+
"""Writes the files returned by the API to target_folder. None content deletes the file.
|
|
154
|
+
|
|
155
|
+
Every written file ends with a newline - whole-file rewrites come back from the API without one. The
|
|
156
|
+
added newline is also written back into response_files, so callers that diff response_files against
|
|
157
|
+
the folder afterwards see exactly what is on disk. Content is written byte-for-byte, without newline
|
|
158
|
+
translation, so the disk matches response_files on every platform.
|
|
159
|
+
"""
|
|
146
160
|
for file_name in response_files:
|
|
147
161
|
full_file_name = os.path.join(target_folder, file_name)
|
|
148
162
|
|
|
@@ -156,9 +170,11 @@ def store_response_files(target_folder, response_files, existing_files):
|
|
|
156
170
|
|
|
157
171
|
continue
|
|
158
172
|
|
|
173
|
+
response_files[file_name] = ensure_final_newline(response_files[file_name])
|
|
174
|
+
|
|
159
175
|
os.makedirs(os.path.dirname(full_file_name), exist_ok=True)
|
|
160
176
|
|
|
161
|
-
with open(full_file_name, "w", encoding="utf-8") as f:
|
|
177
|
+
with open(full_file_name, "w", encoding="utf-8", newline="") as f:
|
|
162
178
|
f.write(response_files[file_name])
|
|
163
179
|
|
|
164
180
|
if file_name not in existing_files:
|
tests/test_file_utils.py
CHANGED
|
@@ -3,7 +3,9 @@ import tempfile
|
|
|
3
3
|
|
|
4
4
|
import pytest
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
import file_utils
|
|
7
|
+
from diff_utils import get_code_diff
|
|
8
|
+
from file_utils import get_existing_files_content, load_linked_resources, store_response_files
|
|
7
9
|
from plain2code_exceptions import UnsupportedBase64Content, UnsupportedResourceType
|
|
8
10
|
from plain2code_utils import MAX_BASE64_BLOB_LENGTH
|
|
9
11
|
|
|
@@ -82,11 +84,91 @@ def test_load_linked_resources_real_base64_image_raises(template_dir):
|
|
|
82
84
|
|
|
83
85
|
|
|
84
86
|
def test_store_response_files_writes_unicode_as_utf8(template_dir):
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
content = "Location 📍 marker"
|
|
87
|
+
"""A non-cp1252 character (📍 U+1F4CD) is written as UTF-8, whatever the platform's default encoding."""
|
|
88
|
+
content = "Location 📍 marker\n"
|
|
88
89
|
store_response_files(template_dir, {"notes.md": content}, [])
|
|
89
90
|
|
|
90
91
|
file_path = os.path.join(template_dir, "notes.md")
|
|
91
92
|
with open(file_path, "rb") as f:
|
|
92
93
|
assert f.read().decode("utf-8") == content
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def _read_bytes(folder, file_name):
|
|
97
|
+
"""Returns a file's content exactly as stored on disk, without newline translation."""
|
|
98
|
+
with open(os.path.join(folder, file_name), "rb") as f:
|
|
99
|
+
return f.read().decode("utf-8")
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
@pytest.mark.parametrize(
|
|
103
|
+
"content, expected",
|
|
104
|
+
[
|
|
105
|
+
("class Foo\nend", "class Foo\nend\n"),
|
|
106
|
+
("class Foo\nend\n", "class Foo\nend\n"),
|
|
107
|
+
("class Foo\nend\n\n", "class Foo\nend\n\n"),
|
|
108
|
+
("class Foo\r\nend\r\n", "class Foo\r\nend\r\n"),
|
|
109
|
+
("", ""),
|
|
110
|
+
],
|
|
111
|
+
)
|
|
112
|
+
def test_store_response_files_ends_every_text_file_with_a_newline(template_dir, content, expected):
|
|
113
|
+
"""A missing final newline is added, as linters such as RuboCop, ESLint and Ruff require.
|
|
114
|
+
|
|
115
|
+
An existing final newline is not doubled, and empty content stays empty.
|
|
116
|
+
"""
|
|
117
|
+
store_response_files(template_dir, {"app/foo.rb": content}, [])
|
|
118
|
+
|
|
119
|
+
assert _read_bytes(template_dir, "app/foo.rb") == expected
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def test_store_response_files_hands_back_the_content_it_wrote(template_dir):
|
|
123
|
+
"""response_files holds the content as written, so diffs taken after storing match the disk.
|
|
124
|
+
|
|
125
|
+
The fix journal and the conformance fixes handed to the unit tests fixer take such diffs.
|
|
126
|
+
"""
|
|
127
|
+
response_files = {"app/foo.rb": "class Foo\nend", "app/bar.rb": "class Bar\nend\n"}
|
|
128
|
+
|
|
129
|
+
store_response_files(template_dir, response_files, [])
|
|
130
|
+
|
|
131
|
+
assert response_files == {"app/foo.rb": "class Foo\nend\n", "app/bar.rb": "class Bar\nend\n"}
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def test_rewriting_a_file_without_its_final_newline_does_not_change_it(template_dir):
|
|
135
|
+
"""A rewrite that drops only the final newline leaves the file byte-identical and produces no diff."""
|
|
136
|
+
existing_files = store_response_files(template_dir, {"app/foo.rb": "class Foo\nend\n"}, [])
|
|
137
|
+
existing_files_content = get_existing_files_content(template_dir, existing_files)
|
|
138
|
+
|
|
139
|
+
rewrite = {"app/foo.rb": "class Foo\nend"}
|
|
140
|
+
store_response_files(template_dir, rewrite, existing_files)
|
|
141
|
+
|
|
142
|
+
assert get_existing_files_content(template_dir, existing_files) == existing_files_content
|
|
143
|
+
assert get_code_diff(rewrite, existing_files_content) == {}
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def test_store_response_files_still_deletes_a_file_whose_content_is_none(template_dir):
|
|
147
|
+
"""None content still deletes the file and removes it from existing_files, and is not turned into a newline."""
|
|
148
|
+
existing_files = store_response_files(template_dir, {"app/foo.rb": "class Foo\nend\n"}, [])
|
|
149
|
+
|
|
150
|
+
response_files = {"app/foo.rb": None}
|
|
151
|
+
store_response_files(template_dir, response_files, existing_files)
|
|
152
|
+
|
|
153
|
+
assert not os.path.exists(os.path.join(template_dir, "app/foo.rb"))
|
|
154
|
+
assert existing_files == []
|
|
155
|
+
assert response_files == {"app/foo.rb": None}
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def test_store_response_files_writes_the_same_bytes_where_text_mode_writes_crlf(template_dir, monkeypatch):
|
|
159
|
+
"""Files hold exactly the normalized content even where text mode writes CRLF line endings (native Windows)."""
|
|
160
|
+
# Imported here: isort 8 and isort 9 disagree on which section a top-level `import _pyio` belongs to.
|
|
161
|
+
import _pyio
|
|
162
|
+
|
|
163
|
+
# Python's reference io (_pyio) takes its line separator from os.linesep, so here it translates like Windows.
|
|
164
|
+
monkeypatch.setattr(os, "linesep", "\r\n")
|
|
165
|
+
monkeypatch.setattr(file_utils, "open", _pyio.open, raising=False)
|
|
166
|
+
with _pyio.open(os.path.join(template_dir, "probe.txt"), "w") as probe:
|
|
167
|
+
probe.write("\n")
|
|
168
|
+
assert _read_bytes(template_dir, "probe.txt") == "\r\n"
|
|
169
|
+
|
|
170
|
+
response_files = {"app/foo.rb": "class Foo\nend", "app/bar.rb": "class Bar\r\nend\r\n"}
|
|
171
|
+
store_response_files(template_dir, response_files, [])
|
|
172
|
+
|
|
173
|
+
assert _read_bytes(template_dir, "app/foo.rb") == response_files["app/foo.rb"] == "class Foo\nend\n"
|
|
174
|
+
assert _read_bytes(template_dir, "app/bar.rb") == response_files["app/bar.rb"] == "class Bar\r\nend\r\n"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|