From fad52f97c7455426145de6a6ba29f021d42dca2a Mon Sep 17 00:00:00 2001 From: Sourabh Bajaj Date: Fri, 27 Jan 2017 15:46:30 -0800 Subject: [PATCH 1/2] Cleanup files after the tests end --- sdks/python/apache_beam/examples/snippets/snippets_test.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sdks/python/apache_beam/examples/snippets/snippets_test.py b/sdks/python/apache_beam/examples/snippets/snippets_test.py index 4827e94c8a15..a6a032e829b0 100644 --- a/sdks/python/apache_beam/examples/snippets/snippets_test.py +++ b/sdks/python/apache_beam/examples/snippets/snippets_test.py @@ -427,14 +427,18 @@ def setUp(self): # real data. beam.io.ReadFromText = SnippetsTest.DummyReadTransform beam.io.WriteToText = SnippetsTest.DummyWriteTransform + self.files = [] def tearDown(self): beam.io.ReadFromText = self.old_read_from_text beam.io.WriteToText = self.old_write_to_text + # Cleanup all the temporary files created in the test + map(os.remove, self.files) def create_temp_file(self, contents=''): with tempfile.NamedTemporaryFile(delete=False) as f: f.write(contents) + self.files.append(f.name) return f.name def get_output(self, path, sorted_output=True, suffix=''): @@ -560,6 +564,8 @@ def test_model_textio_compressed(self): gzip_file_name = temp_path + '.gz' with open(temp_path) as src, gzip.open(gzip_file_name, 'wb') as dst: dst.writelines(src) + # Add the temporary gzip file to be cleaned up as well. + self.files.append(gzip_file_name) snippets.model_textio_compressed( {'read': gzip_file_name}, ['aa', 'bb', 'cc']) From 7af0efd397885e50d5f2c73fb6d0c5da8799ea5f Mon Sep 17 00:00:00 2001 From: Sourabh Bajaj Date: Tue, 7 Feb 2017 08:59:19 -0800 Subject: [PATCH 2/2] Review comments --- .../python/apache_beam/examples/snippets/snippets_test.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sdks/python/apache_beam/examples/snippets/snippets_test.py b/sdks/python/apache_beam/examples/snippets/snippets_test.py index a6a032e829b0..95c959b806c3 100644 --- a/sdks/python/apache_beam/examples/snippets/snippets_test.py +++ b/sdks/python/apache_beam/examples/snippets/snippets_test.py @@ -427,18 +427,18 @@ def setUp(self): # real data. beam.io.ReadFromText = SnippetsTest.DummyReadTransform beam.io.WriteToText = SnippetsTest.DummyWriteTransform - self.files = [] + self.temp_files = [] def tearDown(self): beam.io.ReadFromText = self.old_read_from_text beam.io.WriteToText = self.old_write_to_text # Cleanup all the temporary files created in the test - map(os.remove, self.files) + map(os.remove, self.temp_files) def create_temp_file(self, contents=''): with tempfile.NamedTemporaryFile(delete=False) as f: f.write(contents) - self.files.append(f.name) + self.temp_files.append(f.name) return f.name def get_output(self, path, sorted_output=True, suffix=''): @@ -565,7 +565,7 @@ def test_model_textio_compressed(self): with open(temp_path) as src, gzip.open(gzip_file_name, 'wb') as dst: dst.writelines(src) # Add the temporary gzip file to be cleaned up as well. - self.files.append(gzip_file_name) + self.temp_files.append(gzip_file_name) snippets.model_textio_compressed( {'read': gzip_file_name}, ['aa', 'bb', 'cc'])