Skip to content

Commit 222ad6c

Browse files
committed
Increase tests coverage.
1 parent 0ffc4a5 commit 222ad6c

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

tests/test.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import time
44
import unittest
55
from datetime import datetime, timedelta
6+
from decimal import Decimal
67

78
import fsutil
89

@@ -666,6 +667,21 @@ def test_get_parent_dir(self):
666667
s = "/root/a/b/c/Document.txt"
667668
self.assertEqual(fsutil.get_parent_dir(s, 6), "/")
668669

670+
def test_get_unique_name(self):
671+
path = self.temp_path("a/b/c")
672+
fsutil.create_dir(path)
673+
name = fsutil.get_unique_name(
674+
path,
675+
prefix="custom-prefix",
676+
suffix="custom-suffix",
677+
extension="txt",
678+
separator="_",
679+
)
680+
basename, extension = fsutil.split_filename(name)
681+
self.assertTrue(basename.startswith("custom-prefix_"))
682+
self.assertTrue(basename.endswith("_custom-suffix"))
683+
self.assertEqual(extension, "txt")
684+
669685
def test_is_dir(self):
670686
path = self.temp_path("a/b/")
671687
self.assertFalse(fsutil.is_dir(path))
@@ -1122,11 +1138,16 @@ def test_write_file(self):
11221138
def test_write_file_json(self):
11231139
path = self.temp_path("a/b/c.json")
11241140
now = datetime.now()
1125-
data = {"test": "Hello World", "test_datetime": now}
1141+
dec = Decimal("3.33")
1142+
data = {
1143+
"test": "Hello World",
1144+
"test_datetime": now,
1145+
"test_decimal": dec,
1146+
}
11261147
fsutil.write_file_json(self.temp_path("a/b/c.json"), data=data)
11271148
self.assertEqual(
11281149
fsutil.read_file(path),
1129-
f"""{{"test": "Hello World", "test_datetime": "{now.isoformat()}"}}""",
1150+
f"""{{"test": "Hello World", "test_datetime": "{now.isoformat()}", "test_decimal": "{dec}"}}""",
11301151
)
11311152

11321153
def test_write_file_with_append(self):

0 commit comments

Comments
 (0)