-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from didix21/missing-file-name
Fix #37: Add .md extension if name contains md word
- Loading branch information
Showing
2 changed files
with
76 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# Python | ||
# | ||
# This module implements tests for MdUtils class. | ||
# | ||
# This file is part of mdutils. https://github.com/didix21/mdutils | ||
# | ||
# MIT License: (C) 2020 Dídac Coll | ||
|
||
from unittest import TestCase | ||
from mdutils.fileutils import MarkDownFile | ||
import tempfile | ||
import os | ||
|
||
|
||
class TestMarkdownFile(TestCase): | ||
|
||
def test_create_file(self): | ||
with tempfile.TemporaryDirectory() as tmp: | ||
os.chdir(tmp) | ||
file = MarkDownFile('Test_file') | ||
self.assertEqual(file.file_name, 'Test_file.md') | ||
|
||
def test_create_file_case_0(self): | ||
with tempfile.TemporaryDirectory() as tmp: | ||
os.chdir(tmp) | ||
file = MarkDownFile('Test_filemd') | ||
self.assertEqual(file.file_name, 'Test_filemd.md') | ||
|
||
def test_create_file_case_1(self): | ||
with tempfile.TemporaryDirectory() as tmp: | ||
os.chdir(tmp) | ||
file = MarkDownFile('Test_file.md') | ||
self.assertEqual(file.file_name, 'Test_file.md') | ||
|
||
def test_rewrite_all_file(self): | ||
expected_content = "Write some content" | ||
file_name = 'Test_file.md' | ||
with tempfile.TemporaryDirectory() as tmp: | ||
os.chdir(tmp) | ||
file = MarkDownFile(file_name) | ||
file.rewrite_all_file(expected_content) | ||
with open(file_name, 'r') as actual_md: | ||
self.assertEqual(actual_md.read(), expected_content) | ||
|
||
def test_append_end(self): | ||
expected_content = "Write some content and some data" | ||
file_name = 'Test_file.md' | ||
with tempfile.TemporaryDirectory() as tmp: | ||
os.chdir(tmp) | ||
file = MarkDownFile(file_name) | ||
file.rewrite_all_file("Write some content") | ||
file.append_end(" and some data") | ||
with open(file_name, 'r') as actual_md: | ||
self.assertEqual(actual_md.read(), expected_content) | ||
|
||
def test_append_second_line(self): | ||
expected_content = "This is the 1st line\nThis is the 2nd line\nThis is the 3th line\nThis is the 4th line" | ||
file_name = 'Test_file.md' | ||
with tempfile.TemporaryDirectory() as tmp: | ||
os.chdir(tmp) | ||
file = MarkDownFile(file_name) | ||
file.rewrite_all_file("This is the 1st line\nThis is the 2nd line\nThis is the 4th line") | ||
file.append_after_second_line("This is the 3th line") | ||
with open(file_name, 'r') as actual_md: | ||
self.assertEqual(actual_md.read(), expected_content) | ||
|
||
def test_read(self): | ||
expected_content = "This is the expected content after reading the file" | ||
file_name = 'Test_file.md' | ||
with tempfile.TemporaryDirectory() as tmp: | ||
os.chdir(tmp) | ||
with open(file_name, 'w') as file: | ||
file.write(expected_content) | ||
|
||
self.assertEqual(MarkDownFile.read_file(file_name), expected_content) |