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.

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

66 - Rewrite a file with new data.
77 - Write at the end of the file."""
88
9- def __init__(self, name=''):
9+ def __init__(self, name='', tmp=''):
1010 """Creates a markdown file, if name is not empty.
1111 :param str name: file name"""
12+ import os
1213 if name:
14+ self.dirname = tmp if tmp else os.getcwd()
1315 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')
1517 self.file.close()
1618
1719 def rewrite_all_file(self, data):
1820 """Rewrite all the data of a Markdown file by ``data``.
1921
2022 :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:
2224 self.file.write(data)
2325
2426 def append_end(self, data):
2527 """Write at the last position of a Markdown file.
2628
2729 :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:
2931 self.file.write(data)
3032
3133 def append_after_second_line(self, data):
3234 """Write after the file's first line.
3335
3436 :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:
3638 file_data = self.file.read() # Save all the file's content
3739 self.file.seek(0, 0) # Place file pointer at the beginning
3840 first_line = self.file.readline() # Read the first line

The check that tells the two apart

failpass·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.

Other bugs found in didix21/mdutils