@@ -9,8 +9,15 @@ def setUp(self):
9
9
self .test_file = os .path .join (self .directory , 'testfile.txt' )
10
10
# Create a test file with known content
11
11
with open (self .test_file , 'w' ) as f :
12
- f .write ("line1\\ nline2\\ nline3\\ nline4\\ nline5\\ n" )
13
-
12
+ for i in range (5 ):
13
+ f .write (f'line{ i + 1 } \n ' )
14
+
15
+ # Create a prompt file with the summary
16
+ summary = summarize_directory (self .directory , gitignore_file = self .gitignore_file )
17
+ prompt_file = os .path .join (self .directory , 'Context_for_ChatGPT.md' )
18
+ with open (prompt_file , "w" , encoding = "utf-8" ) as f :
19
+ f .write (summary )
20
+
14
21
def tearDown (self ):
15
22
# Remove the test file after tests
16
23
if os .path .isfile (self .test_file ):
@@ -19,28 +26,25 @@ def tearDown(self):
19
26
def test_gitignore (self ):
20
27
# Test that .gitignore is working by checking that LICENSE is not in the summary
21
28
summary = summarize_directory (self .directory , gitignore_file = self .gitignore_file )
22
- self .assertNotIn ('build.README .md' , summary )
29
+ self .assertNotIn ('## ./Context_for_ChatGPT .md' , summary )
23
30
24
31
def test_include (self ):
25
32
# Test include and exclude arguments
26
33
summary = summarize_directory (self .directory , gitignore_file = self .gitignore_file , include_exts = ['.md' ])
27
- self .assertIn ('python summarize_directory.py' , summary )
34
+ self .assertIn ('python summarize_directory.py' , summary ) # line from readme should be included
28
35
29
36
def test_exclude (self ):
30
37
# Test exclude argument
31
38
summary = summarize_directory (self .directory , gitignore_file = self .gitignore_file , exclude_exts = ['.md' ])
32
39
self .assertNotIn ('python summarize_directory.py' , summary ) # README.md should be excluded
33
-
40
+
34
41
def test_max_lines (self ):
35
- # Test max_lines argument
42
+ # Test the max_lines argument
36
43
max_lines = 3
37
- summary = summarize_directory (self .directory , max_lines = max_lines )
38
- file_summary_start = "## {}/testfile.txt\\ n" .format (self .directory .replace ("\\ \\ " , "/" ))
39
- file_summary = "line1\\ nline2\\ nline3"
40
- # Check that the file summary in summary includes only max_lines lines
41
- self .assertIn (file_summary_start , summary )
42
- self .assertIn (file_summary , summary )
43
- self .assertNotIn ("line4\\ nline5" , summary )
44
+ summary = summarize_directory (self .directory , gitignore_file = self .gitignore_file , max_lines = max_lines )
45
+ # Check if the 'testfile.txt' content is truncated to 'max_lines' lines
46
+ self .assertNotIn ('line4' , summary )
47
+ self .assertNotIn ('line5' , summary )
44
48
45
49
if __name__ == '__main__' :
46
50
unittest .main ()
0 commit comments