def test_logging_enabled(self): """ Test local log enabled by default. """ test_file = FileAsObj() self.assertIsNotNone(str(test_file.log)) test_file.log('FINDME') self.assertTrue('FINDME' in str(test_file.log)) self.assertTrue('FINDME' in test_file.log.trace)
my_file.rm(my_file.grep('foo')) # # Check for line in file, if exists remove it if 'foo bar' in my_file: my_file.rm('foo bar') # or my_file.rm(my_file.check('foo bar')) # or my_file.rm('foo bar') # OK if line not found. # # Now that you've changed data let's save it back to disk. my_file.save() # or my_file.write() # of if my_file.virgin is False: my_file.save() # # NOTE: you'll probably never need to worry about this part. If it doesn't make sense, just ignore it. # As things are checked or changed with FileAsObj an internal log is updated. # To view it: print(my_file.log) # If you want to manually add something: my_file.log('A manual log entry') # This does not change the file, just the log attribute of the object.
def test_string_log_call(self): """ Test __call__ method of log subclass. """ test_file = FileAsObj() self.assertIsNone(test_file.log('test'))
def test_logging_disable(self): """ Test disabled local log. """ test_file = FileAsObj(logging=False) test_file.log('logging disabled this will not be saved') self.assertTrue(str(test_file.log) == '') self.assertTrue(test_file.log.trace == '')
# NOTE: this is dangerous and rarely needed. my_file.rm(my_file.grep('foo')) # # Check for line in file, if exists remove it if 'foo bar' in my_file: my_file.rm('foo bar') # or my_file.rm(my_file.check('foo bar')) # or my_file.rm('foo bar') # OK if line not found. # # Now that you've changed data let's save it back to disk. my_file.save() # or my_file.write() # of if my_file.virgin is False: my_file.save() # # NOTE: you'll probably never need to worry about this part. If it doesn't make sense, just ignore it. # As things are checked or changed with FileAsObj an internal log is updated. # To view it: print(my_file.log) # If you want to manually add something: my_file.log( 'A manual log entry' ) # This does not change the file, just the log attribute of the object.
def example_manually_update_change_log(): """ You can inject an arbitrary message to the log sub-class by calling it. """ my_file = FileAsObj('/tmp/example_file.txt') my_file.log('A manual log entry.')