Skip to content

Commit

Permalink
Fix tests that have the same name
Browse files Browse the repository at this point in the history
Note that this means that tests that were previously being masked by other
tests with the same name will now be run.

There is a fix included for one such test.
  • Loading branch information
chadrik committed Jan 9, 2020
1 parent 551a21d commit f15424d
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 21 deletions.
4 changes: 2 additions & 2 deletions sdks/python/apache_beam/io/fileio_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def test_match_all_two_directories(self):

assert_that(files_pc, equal_to(files))

def test_match_files_one_directory_failure(self):
def test_match_files_one_directory_failure1(self):
directories = [
'%s%s' % (self._new_tempdir(), os.sep),
'%s%s' % (self._new_tempdir(), os.sep)]
Expand All @@ -114,7 +114,7 @@ def test_match_files_one_directory_failure(self):

assert_that(files_pc, equal_to(files))

def test_match_files_one_directory_failure(self):
def test_match_files_one_directory_failure2(self):
directories = [
'%s%s' % (self._new_tempdir(), os.sep),
'%s%s' % (self._new_tempdir(), os.sep)]
Expand Down
11 changes: 9 additions & 2 deletions sdks/python/apache_beam/io/filesystems_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import logging
import os
import shutil
import sys
import tempfile
import unittest

Expand All @@ -49,6 +50,12 @@ def _join(first_path, *paths):

class FileSystemsTest(unittest.TestCase):

@classmethod
def setUpClass(cls):
# Method has been renamed in Python 3
if sys.version_info[0] < 3:
cls.assertCountEqual = cls.assertItemsEqual

def setUp(self):
self.tmpdir = tempfile.mkdtemp()

Expand Down Expand Up @@ -132,7 +139,7 @@ def test_match_file_exception(self):
FileSystems.match([None])
self.assertEqual(list(error.exception.exception_details), [None])

def test_match_directory(self):
def test_match_directory_with_files(self):
path1 = os.path.join(self.tmpdir, 'f1')
path2 = os.path.join(self.tmpdir, 'f2')
open(path1, 'a').close()
Expand All @@ -142,7 +149,7 @@ def test_match_directory(self):
path = os.path.join(self.tmpdir, '*')
result = FileSystems.match([path])[0]
files = [f.path for f in result.metadata_list]
self.assertEqual(files, [path1, path2])
self.assertCountEqual(files, [path1, path2])

def test_match_directory(self):
result = FileSystems.match([self.tmpdir])[0]
Expand Down
7 changes: 0 additions & 7 deletions sdks/python/apache_beam/io/restriction_trackers_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,6 @@ def test_check_done_after_try_claim_past_end_of_range(self):
self.assertFalse(tracker.try_claim(220))
tracker.check_done()

def test_check_done_after_try_claim_past_end_of_range(self):
tracker = OffsetRestrictionTracker(OffsetRange(100, 200))
self.assertTrue(tracker.try_claim(150))
self.assertTrue(tracker.try_claim(175))
self.assertFalse(tracker.try_claim(200))
tracker.check_done()

def test_check_done_after_try_claim_right_before_end_of_range(self):
tracker = OffsetRestrictionTracker(OffsetRange(100, 200))
self.assertTrue(tracker.try_claim(150))
Expand Down
19 changes: 10 additions & 9 deletions sdks/python/apache_beam/io/tfrecordio_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ def test_process_deflate(self):
validate=True))
assert_that(result, equal_to([b'foo', b'bar']))

def test_process_gzip(self):
def test_process_gzip_with_coder(self):
with TempDir() as temp_dir:
path = temp_dir.create_temp_file('result')
_write_file_gzip(path, FOO_BAR_RECORD_BASE64)
Expand All @@ -303,27 +303,28 @@ def test_process_gzip(self):
validate=True))
assert_that(result, equal_to([b'foo', b'bar']))

def test_process_auto(self):
def test_process_gzip_without_coder(self):
with TempDir() as temp_dir:
path = temp_dir.create_temp_file('result.gz')
path = temp_dir.create_temp_file('result')
_write_file_gzip(path, FOO_BAR_RECORD_BASE64)
with TestPipeline() as p:
result = (p
| ReadFromTFRecord(
path,
coder=coders.BytesCoder(),
compression_type=CompressionTypes.AUTO,
validate=True))
compression_type=CompressionTypes.GZIP))
assert_that(result, equal_to([b'foo', b'bar']))

def test_process_gzip(self):
def test_process_auto(self):
with TempDir() as temp_dir:
path = temp_dir.create_temp_file('result')
path = temp_dir.create_temp_file('result.gz')
_write_file_gzip(path, FOO_BAR_RECORD_BASE64)
with TestPipeline() as p:
result = (p
| ReadFromTFRecord(
path, compression_type=CompressionTypes.GZIP))
path,
coder=coders.BytesCoder(),
compression_type=CompressionTypes.AUTO,
validate=True))
assert_that(result, equal_to([b'foo', b'bar']))

def test_process_gzip_auto(self):
Expand Down
2 changes: 1 addition & 1 deletion sdks/python/apache_beam/testing/util_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def test_assert_that_passes_is_not_empty(self):
with TestPipeline() as p:
assert_that(p | Create([1, 2, 3]), is_not_empty())

def test_assert_that_fails_on_empty_expected(self):
def test_assert_that_fails_on_is_not_empty_expected(self):
with self.assertRaises(BeamAssertException):
with TestPipeline() as p:
assert_that(p | Create([]), is_not_empty())
Expand Down

0 comments on commit f15424d

Please sign in to comment.