def store_file(self): if not self.is_duplicate_file(): # skip exact duplicates self.change_file_name_if_already_exists() file_writer.store_file(self._full_path, self.get_content_to_save()) md5 = self._json['attachment'][self._attachment_id]['md5'] name = self._json['attachment'][self._attachment_id]['name'] self._parent_notebook.attachment_md5_file_name_dict[md5] = name
def test_file_writer_bytes_io(tmp_path): content = BytesIO(b"Hello World") file_path = Path(tmp_path, "file1.file") file_writer.store_file(file_path, content) result = file_path.read_bytes() assert result == b"Hello World"
def test_file_writer_string(tmp_path): content = "Hello World" file_path = Path(tmp_path, "file1.file") file_writer.store_file(file_path, content) result = file_path.read_text() assert result == content
def test_file_writer_bytes(tmp_path): content = b'Hello World' file_path = Path(tmp_path, "file1.file") file_writer.store_file(file_path, content) result = file_path.read_bytes() assert result == content
def test_file_writer_invalid_type_content(tmp_path, caplog): content = 23 file_path = Path(tmp_path, "file1.file") file_writer.store_file(file_path, content) assert len(caplog.records) > 0 for record in caplog.records: assert record.levelname == "WARNING"
def test_file_writer_bytes_io_invalid_path(tmp_path, caplog): content = BytesIO(b"Hello World") file_path = Path(tmp_path, "ddsf/dsfsdf/dfsd", "file1.file") file_writer.store_file(file_path, content) assert len(caplog.records) > 0 for record in caplog.records: assert record.levelname == "ERROR" assert 'No such file or directory' in record.message
def test_file_writer_bytes_io_existing_directory(tmp_path, caplog): content = BytesIO(b"Hello World") file_path = Path(tmp_path) file_writer.store_file(file_path, content) assert len(caplog.records) > 1
def test_file_writer_string_existing_directory(tmp_path, caplog): content = "Hello World" file_path = Path(tmp_path) file_writer.store_file(file_path, content) assert len(caplog.records) > 1
def store_file(self): file_writer.store_file(self._full_path, self.get_content_to_save())
def _store_file(note_page, bar=None): file_writer.store_file(note_page.full_path, note_page.converted_content) if bar: bar()