Beispiel #1
0
  def test_temp_dir_removes_files(self):
    with utils.TempDir() as tempdir:
      dir_path = tempdir.get_path()
      file_path = tempdir.create_temp_file()
      self.assertTrue(os.path.exists(dir_path))
      self.assertTrue(os.path.exists(file_path))

    self.assertFalse(os.path.exists(dir_path))
    self.assertFalse(os.path.exists(file_path))
Beispiel #2
0
    def test_temp_file_field_correct(self):
        with utils.TempDir() as tempdir:
            filename = tempdir.create_temp_file(
                suffix='.txt', lines=[b'line1\n', b'line2\n', b'line3\n'])
            self.assertTrue(filename.endswith('.txt'))

            with open(filename, 'rb') as f:
                self.assertEqual(f.readline(), b'line1\n')
                self.assertEqual(f.readline(), b'line2\n')
                self.assertEqual(f.readline(), b'line3\n')