9 def testPtbRawData(self):
10 tmpdir = tf.test.get_temp_dir()
11 for suffix in "train", "valid", "test":
12 filename = os.path.join(tmpdir, "ptb.%s.txt" % suffix)
13 with tf.gfile.GFile(filename, "w") as fh:
14 fh.write(self._string_data)
15 # Smoke test
16 output = reader.ptb_raw_data(tmpdir)
17 self.assertEqual(len(output), 4)
測試reader.ptb_raw_data是否有正確運作。他的流程是產生一個暫存資料夾,寫入三個檔案ptb.train.txt, ptb.valid.txt, ptb.test.txt,把PtbReaderTest的_string_data
寫入這三個檔案,最後檢查output length是否等於4。
Figure 1: Flow chart of testPtbRawData.py file