def test_record(self): """Testing the record adding method. """ newRecord = 'abc' r = Recorder('testRecorder') r.addRecord(newRecord) self.assertEqual(r.records, [newRecord]) # Record list correctness with open(r.path, 'r') as fin: self.assertEqual(fin.read(), 'abc') # Record file of correct data
def test_recordWithoutAutoSave(self): """Testing the record adding method without auto saving. """ newRecord = 'abc' r = Recorder('testRecorder') r.addRecord(newRecord, False) self.assertEqual(r.records, [newRecord]) # Record list correctness with open(r.path, 'r') as fin: self.assertFalse(fin.read()) # Record file content correctness
def test_recordExists(self): """Testing the method of checking the existence of record. """ r = Recorder('testRecorder') self.assertFalse(r.recordExists()) # Record not exists at initial state newRecord = ['abc'] r.addRecord(newRecord, False) self.assertTrue(r.recordExists()) # Record exists after adding a record
def test_recordAutoSaveAfterRecordWithoutAutoSave(self): """Testing the record adding method after exercising an adding method without auto saving. """ newRecord = 'abc' r = Recorder('testRecorder') r.addRecord(newRecord, False) self.assertEqual(r.records, [newRecord]) with open(r.path, 'r') as fin: self.assertFalse(fin.read()) # Record file content correctness newRecord = 'klm' r.addRecord(newRecord) with open(r.path, 'r') as fin: txt = fin.read() self.assertNotEqual(txt, 'abc') self.assertEqual(txt, 'abc\nklm') # Newest record was saved together with the previous unsaved record
def test_recordWithoutAutoSaveAfterRecordAutoSave(self): """Testing the record adding method without auto saving after exercising an adding method with auto saving. """ newRecord = 'abc' r = Recorder('testRecorder') r.addRecord(newRecord) self.assertEqual(r.records, ['abc']) # Record list correctness with open(r.path, 'r') as fin: self.assertEqual(fin.read(), 'abc') # Record file content correctness newRecord = 'klm' r.addRecord(newRecord, False) self.assertEqual(r.records, ['abc', 'klm']) # Record list correctness with open(r.path, 'r') as fin: txt = fin.read() self.assertEqual(txt, 'abc') # Record file remained unchanged self.assertNotEqual(txt, 'abc\nklm')
def test_recordAmount(self): """Testing the method of checking the amount of record. """ r = Recorder('testRecorder') self.assertEqual(r.recordAmount(), 0) # Record amount correctness of initial state newRecord = 'abc' r.addRecord(newRecord, False) self.assertEqual(r.recordAmount(), 1) # Record amount correctness after adding a record for i in range(10): r.addRecord(str(i), False) self.assertEqual(r.recordAmount(), 11) # Record amount correctness after adding a record for serveral times newRecords = ['aaa', 'bbb', 'ccc'] r.addRecords(newRecords) self.assertEqual(r.recordAmount(), 14) # Record amount correctness after adding records