One function
MarkDownFile in didix21/mdutils
The author described this change as “Modify tests to fix flakiness”. It counts as a record because the check below fails on the code as it stood at 780974b94 and passes on 5a701281b, with nothing else changed between the two runs.
Projectdidix21/mdutils
Fix saved2022-10-27
Sharing licenceMIT · LICENSE.txt
Change size+7 −5
What the code was meant to do, written into the code itself as a docstring
MarkDownFile class creates a new file of MarkDown extension. Features available are: - Create a file. - Rewrite a file with new data. - Write at the end of the file.
The change
| 6 | 6 | - Rewrite a file with new data. | |
| 7 | 7 | - Write at the end of the file.""" | |
| 8 | 8 | ||
| 9 | - | def __init__(self, name=''): | |
| 9 | + | def __init__(self, name='', tmp=''): | |
| 10 | 10 | """Creates a markdown file, if name is not empty. | |
| 11 | 11 | :param str name: file name""" | |
| 12 | + | import os | |
| 12 | 13 | if name: | |
| 14 | + | self.dirname = tmp if tmp else os.getcwd() | |
| 13 | 15 | self.file_name = name if name.endswith('.md') else name + '.md' | |
| 14 | - | self.file = open(self.file_name, 'w+', encoding='UTF-8') | |
| 16 | + | self.file = open(f'{self.dirname}/{self.file_name}', 'w+', encoding='UTF-8') | |
| 15 | 17 | self.file.close() | |
| 16 | 18 | ||
| 17 | 19 | def rewrite_all_file(self, data): | |
| 18 | 20 | """Rewrite all the data of a Markdown file by ``data``. | |
| 19 | 21 | ||
| 20 | 22 | :param str data: is a string containing all the data that is written in the markdown file.""" | |
| 21 | - | with open(self.file_name, 'w', encoding='utf-8') as self.file: | |
| 23 | + | with open(f'{self.dirname}/{self.file_name}', 'w', encoding='utf-8') as self.file: | |
| 22 | 24 | self.file.write(data) | |
| 23 | 25 | ||
| 24 | 26 | def append_end(self, data): | |
| 25 | 27 | """Write at the last position of a Markdown file. | |
| 26 | 28 | ||
| 27 | 29 | :param str data: is a string containing all the data that is written in the markdown file.""" | |
| 28 | - | with open(self.file_name, 'a', encoding='utf-8') as self.file: | |
| 30 | + | with open(f'{self.dirname}/{self.file_name}', 'a', encoding='utf-8') as self.file: | |
| 29 | 31 | self.file.write(data) | |
| 30 | 32 | ||
| 31 | 33 | def append_after_second_line(self, data): | |
| 32 | 34 | """Write after the file's first line. | |
| 33 | 35 | ||
| 34 | 36 | :param str data: is a string containing all the data that is written in the markdown file.""" | |
| 35 | - | with open(self.file_name, 'r+', encoding='utf-8') as self.file: | |
| 37 | + | with open(f'{self.dirname}/{self.file_name}', 'r+', encoding='utf-8') as self.file: | |
| 36 | 38 | file_data = self.file.read() # Save all the file's content | |
| 37 | 39 | self.file.seek(0, 0) # Place file pointer at the beginning | |
| 38 | 40 | first_line = self.file.readline() # Read the first line |
The check that tells the two apart
fail→pass·tests/test_fileutils/test_fileutils.py::TestMarkdownFile::test_append_end
Check file tests/test_fileutils/test_fileutils.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.
Origin and history
The code before it780974b9431d98a3f9927af4d17fd7dba53b0854
Broken version dated2022-10-10
Modulemdutils.fileutils.fileutils
Units changedMarkDownFile
Fingerprint11f132e476672aa6
Checked2026-08-18 by goldset/0.1
Every field above is generated by our program. None of it is written by hand.