File tree Expand file tree Collapse file tree 3 files changed +11
-24
lines changed
tests/Infrastructure/EventLoggingManager Expand file tree Collapse file tree 3 files changed +11
-24
lines changed Original file line number Diff line number Diff line change 44class EventLoggingManager :
55
66 def __init__ (self , file_utility ):
7- file_path = file_utility .get_root_path () + "\\ filename.txt "
7+ file_path = file_utility .get_root_path () + "\\ MobTimerEvents.log "
88 if not file_utility .file_exists (file_path ):
99 file_utility .create_file (file_path )
Original file line number Diff line number Diff line change 77class FileUtilities (object ):
88 @staticmethod
99 def main_is_frozen ():
10- return (hasattr (sys , "frozen" ) or # new py2exe
11- hasattr (sys , "importers" ) # old py2exe
12- or imp .is_frozen ("__main__" )) # tools/freeze
10+ return (hasattr (sys , "frozen" ) or # new py2exe
11+ hasattr (sys , "importers" ) # old py2exe
12+ or imp .is_frozen ("__main__" )) # tools/freeze
1313
1414 def get_root_path (self ):
1515 if FileUtilities .main_is_frozen ():
1616 return os .path .dirname (sys .executable )
1717 return os .path .dirname (os .path .realpath (__file__ ))
1818
19- def file_exists (self , path ):
20- return exists (path )
19+ def file_exists (self , file_path ):
20+ return exists (file_path )
2121
22- def create_file (self , filePath ):
23- f = open (filePath , "w" )
24- # f.write("Woops! I have deleted the content!")
22+ def create_file (self , file_path ):
23+ f = open (file_path , "w" )
2524 f .close ()
26-
27- # def __init__(self, file_utility):
28- #
29- # if not file_utility.file_exists():
30- # file_utility.create_file("path to file")
Original file line number Diff line number Diff line change 55from Infrastructure .FileUtilities import FileUtilities
66
77
8- # 1. Mock remaining File Utilities function calls
9- # 2. Choose a real name for the log file
10-
118class TestsEventLoggingManager (unittest .TestCase ):
129
1310 def test_log_file_should_be_created_if_doesnt_exist (self ):
14- # Options: Mocks, Fake Files
15-
16- # Arrange: Make sure the file does not exist
1711 file_utility = FileUtilities ()
1812 file_utility .get_root_path = MagicMock (return_value = 'beginning of file path' )
1913 file_utility .file_exists = MagicMock (return_value = False )
2014 file_utility .create_file = MagicMock (return_value = True )
21- # Act: Instantiate EventLoggingManager
22- event_logging_manager = EventLoggingManager (file_utility )
2315
24- # Assert: Verify the file exists
25- file_utility .create_file .assert_called_with (file_utility .get_root_path () + "\\ filename.txt" )
16+ EventLoggingManager (file_utility )
17+
18+ file_utility .create_file .assert_called_with (file_utility .get_root_path () + '\\ MobTimerEvents.log' )
2619
2720
2821if __name__ == '__main__' :
You can’t perform that action at this time.
0 commit comments