6
6
from tempfile import gettempdir
7
7
from unittest import TestCase
8
8
9
+ from tinyscript import b
9
10
from tinyscript .helpers .path import *
10
11
11
12
from utils import *
14
15
class TestHelpersPath (TestCase ):
15
16
@classmethod
16
17
def setUpClass (cls ):
17
- global FILE , FILE2 , MODULE , NOTEX , PATH , SPATH , TEST , TPATH1 , TPATH2
18
+ global FILE , FILE2 , MODULE , NOTEX , PATH , SPATH , TEST , TPATH1 , TPATH2 , TXT
18
19
TEST = "test_dir"
19
20
PATH = Path (TEST , expand = True , create = True )
20
21
SPATH = PATH .joinpath ("test" )
@@ -36,6 +37,7 @@ def setUpClass(cls):
36
37
FILE2 = PATH .joinpath ("test2.txt" )
37
38
SPATH .joinpath ("test.txt" ).touch ()
38
39
NOTEX = Path ("DOES_NOT_EXIST" )
40
+ TXT = "this is a\n test"
39
41
40
42
@classmethod
41
43
def tearDownClass (cls ):
@@ -60,11 +62,11 @@ def test_file_extensions(self):
60
62
self .assertIsNone (FILE .remove ())
61
63
self .assertFalse (FILE .exists ())
62
64
self .assertIsNone (FILE .touch ())
63
- self .assertEqual (FILE .write_text ("this is a test" ), 14 )
64
- self .assertEqual (list (FILE .read_lines ()), [ b"this is a test" ] )
65
- self .assertEqual (list (FILE .read_lines (reverse = True )), [ b"this is a test" ])
66
- self .assertEqual (list (FILE .read_lines (encoding = "utf-8" )), [ "this is a test" ] )
67
- self .assertEqual (list (FILE .read_lines (encoding = "utf-8" , reverse = True )), [ "this is a test" ])
65
+ self .assertEqual (FILE .write_text (TXT ), 15 )
66
+ self .assertEqual (list (FILE .read_lines ()), list ( map ( b , TXT . split ( " \n " ))) )
67
+ self .assertEqual (list (FILE .read_lines (reverse = True )), list ( map ( b , TXT . split ( " \n " )))[:: - 1 ])
68
+ self .assertEqual (list (FILE .read_lines (encoding = "utf-8" )), TXT . split ( " \n " ) )
69
+ self .assertEqual (list (FILE .read_lines (encoding = "utf-8" , reverse = True )), TXT . split ( " \n " )[:: - 1 ])
68
70
self .assertEqual (FILE .choice (), FILE )
69
71
self .assertEqual (FILE .generate (), FILE )
70
72
self .assertRaises (TypeError , FILE .append_text , 0 )
@@ -81,7 +83,7 @@ def test_folder_extensions(self):
81
83
self .assertEqual (str (PATH ), str (Path (TEST ).absolute ()))
82
84
self .assertEqual (Path (TEST ).child , Path ("." ))
83
85
self .assertEqual (SPATH .size , 4096 )
84
- self .assertEqual (PATH .size , [4096 + 4096 + 14 , 8213 ][WINDOWS ]) # PATH + SPATH + FILE
86
+ self .assertEqual (PATH .size , [4096 + 4096 + 15 , 8213 ][WINDOWS ]) # PATH + SPATH + FILE
85
87
self .assertTrue (PATH .choice (".txt" , ".py" , ".other" ).is_samepath (FILE ))
86
88
self .assertIsInstance (PATH .generate (), Path )
87
89
self .assertEqual (list (PATH .iterfiles ()), [FILE .absolute ()])
0 commit comments