def test_second_read(self): ''' Test data changes on second read ''' copyfile(TEST_FILE1, TEST_FILE) fhandle = readfile.ReadFile(root=DATA_DIR) fhandle.read() copyfile(TEST_FILE2, TEST_FILE) fhandle.read() self.assertEqual( fhandle.data, TEST_DATA2, msg='Incorrect data from file on second read' )
def test_cached_read(self): ''' Test data does not change on cached read ''' copyfile(TEST_FILE1, TEST_FILE) fhandle = readfile.ReadFile(root=DATA_DIR) fhandle.read() copyfile(TEST_FILE2, TEST_FILE) fhandle.read() self.assertEqual( fhandle.data, TEST_DATA1, msg='Incorrect data from cached file' )
def test_file_does_not_exist(self): ''' Test instantiation when file does not exist ''' fhandle = readfile.ReadFile(root=DATA_DIR) fhandle.read() self.assertEqual( fhandle.data, None, msg='Incorrect data from nonexistent file' ) self.assertEqual( fhandle.lines, [], msg='Incorrect lines from nonexistent file' )
def test_pid_file(self): ''' Test instantiation when pid is specified ''' copyfile(TEST_PIDFILE1, TEST_PIDFILE) fhandle = readfile.ReadFile(pid=self.pid, root=DATA_DIR) fhandle.read() self.assertEqual( fhandle.data, TEST_DATA1, msg='Incorrect data from file of pid %s' % (self.pid, ) ) self.assertEqual( fhandle.lines, TEST_LINES1, msg='Incorrect lines from file of pid %s' % (self.pid, ) )
def test_readfile(self): ''' Test normal instantiation ''' copyfile(TEST_FILE1, TEST_FILE) fhandle = readfile.ReadFile(root=DATA_DIR) fhandle.read() self.assertEqual( fhandle.data, TEST_DATA1, msg='Incorrect data from file' ) self.assertEqual( fhandle.lines, TEST_LINES1, msg='Incorrect lines from file' ) with self.assertRaises(NotImplementedError): fhandle.normalize()