Cleanup temporary files in textio and avroio tests.

Project: http://git-wip-us.apache.org/repos/asf/incubator-beam/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-beam/commit/f9c565b6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-beam/tree/f9c565b6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-beam/diff/f9c565b6

Branch: refs/heads/python-sdk
Commit: f9c565b6d9c2b7b11e6cba8f1f7354fd4e369193
Parents: 7d988e3
Author: Robert Bradshaw <rober...@gmail.com>
Authored: Sat Sep 24 01:16:43 2016 -0700
Committer: Robert Bradshaw <rober...@google.com>
Committed: Mon Sep 26 12:17:35 2016 -0700

----------------------------------------------------------------------
 sdks/python/apache_beam/io/avroio_test.py | 9 +++++++++
 sdks/python/apache_beam/io/textio_test.py | 5 +++++
 2 files changed, 14 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-beam/blob/f9c565b6/sdks/python/apache_beam/io/avroio_test.py
----------------------------------------------------------------------
diff --git a/sdks/python/apache_beam/io/avroio_test.py 
b/sdks/python/apache_beam/io/avroio_test.py
index 29c4209..c21ed57 100644
--- a/sdks/python/apache_beam/io/avroio_test.py
+++ b/sdks/python/apache_beam/io/avroio_test.py
@@ -34,11 +34,19 @@ import avro.schema as avro_schema
 
 class TestAvro(unittest.TestCase):
 
+  _temp_files = []
+
   def setUp(self):
     # Reducing the size of thread pools. Without this test execution may fail 
in
     # environments with limited amount of resources.
     filebasedsource.MAX_NUM_THREADS_FOR_SIZE_ESTIMATION = 2
 
+  def tearDown(self):
+    for path in self._temp_files:
+      if os.path.exists(path):
+        os.remove(path)
+    self._temp_files = []
+
   RECORDS = [{'name': 'Thomas',
               'favorite_number': 1,
               'favorite_color': 'blue'}, {'name': 'Henry',
@@ -79,6 +87,7 @@ class TestAvro(unittest.TestCase):
         writer.append(self.RECORDS[i % len_records])
       writer.close()
 
+      self._temp_files.append(f.name)
       return f.name
 
   def _write_pattern(self, num_files):

http://git-wip-us.apache.org/repos/asf/incubator-beam/blob/f9c565b6/sdks/python/apache_beam/io/textio_test.py
----------------------------------------------------------------------
diff --git a/sdks/python/apache_beam/io/textio_test.py 
b/sdks/python/apache_beam/io/textio_test.py
index 3fa0f9a..fef2b79 100644
--- a/sdks/python/apache_beam/io/textio_test.py
+++ b/sdks/python/apache_beam/io/textio_test.py
@@ -20,6 +20,7 @@
 import glob
 import gzip
 import logging
+import os
 import tempfile
 import unittest
 import zlib
@@ -330,6 +331,10 @@ class TextSinkTest(unittest.TestCase):
     self.lines = ['Line %d' % d for d in range(100)]
     self.path = tempfile.NamedTemporaryFile().name
 
+  def tearDown(self):
+    if os.path.exists(self.path):
+      os.remove(self.path)
+
   def _write_lines(self, sink, lines):
     f = sink.open(self.path)
     for line in lines:

Reply via email to