avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fo...@apache.org
Subject [avro] branch master updated: AVRO-2437: Fix Py3 test not to omit "test skipped" message (#552)
Date Fri, 12 Jul 2019 08:18:10 GMT
This is an automated email from the ASF dual-hosted git repository.

fokko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/avro.git


The following commit(s) were added to refs/heads/master by this push:
     new 5f3e59b  AVRO-2437: Fix Py3 test not to omit "test skipped" message (#552)
5f3e59b is described below

commit 5f3e59bf4bd2a89a1c676526f22036515c397b94
Author: Kengo Seki <sekikn@apache.org>
AuthorDate: Fri Jul 12 17:18:03 2019 +0900

    AVRO-2437: Fix Py3 test not to omit "test skipped" message (#552)
    
    * AVRO-2437: Fix run_tests.py to show "test skipped" message
    
    * AVRO-2437: Fix Py3 test not to omit "test skipped" message
    
    * Collect import statements into the top of the file
---
 lang/py3/avro/tests/test_datafile.py | 45 ++++++++++++++++++++++++------------
 1 file changed, 30 insertions(+), 15 deletions(-)

diff --git a/lang/py3/avro/tests/test_datafile.py b/lang/py3/avro/tests/test_datafile.py
index ceeab82..2d3576a 100644
--- a/lang/py3/avro/tests/test_datafile.py
+++ b/lang/py3/avro/tests/test_datafile.py
@@ -23,6 +23,18 @@ import os
 import tempfile
 import unittest
 
+try:
+  import snappy
+  HAS_SNAPPY = True
+except ImportError:
+  HAS_SNAPPY = False
+
+try:
+  import zstandard
+  HAS_ZSTANDARD = True
+except ImportError:
+  HAS_ZSTANDARD = False
+
 from avro import datafile
 from avro import io
 from avro import schema
@@ -77,19 +89,20 @@ SCHEMAS_TO_VALIDATE = (
    {'value': {'car': {'value': 'head'}, 'cdr': {'value': None}}}),
 )
 
-CODECS_TO_VALIDATE = ('null', 'deflate')
+def get_codecs_to_validate():
+  codecs = ('null', 'deflate')
 
-try:
-  import snappy
-  CODECS_TO_VALIDATE += ('snappy',)
-except ImportError:
-  logging.warning('Snappy not present, will skip testing it.')
+  if HAS_SNAPPY:
+    codecs += ('snappy',)
+  else:
+    logging.warning('Snappy not present, will skip testing it.')
 
-try:
-  import zstandard
-  CODECS_TO_VALIDATE += ('zstandard',)
-except ImportError:
-  logging.warning('Zstandard not present, will skip testing it.')
+  if HAS_ZSTANDARD:
+    codecs += ('zstandard',)
+  else:
+    logging.warning('Zstandard not present, will skip testing it.')
+
+  return codecs
 
 # ------------------------------------------------------------------------------
 
@@ -125,8 +138,9 @@ class TestDataFile(unittest.TestCase):
 
   def testRoundTrip(self):
     correct = 0
+    codecs_to_validate = get_codecs_to_validate()
     for iexample, (writer_schema, datum) in enumerate(SCHEMAS_TO_VALIDATE):
-      for codec in CODECS_TO_VALIDATE:
+      for codec in codecs_to_validate:
         file_path = self.NewTempFile()
 
         # Write the datum this many times in the data file:
@@ -173,12 +187,13 @@ class TestDataFile(unittest.TestCase):
 
     self.assertEqual(
         correct,
-        len(CODECS_TO_VALIDATE) * len(SCHEMAS_TO_VALIDATE))
+        len(codecs_to_validate) * len(SCHEMAS_TO_VALIDATE))
 
   def testAppend(self):
     correct = 0
+    codecs_to_validate = get_codecs_to_validate()
     for iexample, (writer_schema, datum) in enumerate(SCHEMAS_TO_VALIDATE):
-      for codec in CODECS_TO_VALIDATE:
+      for codec in codecs_to_validate:
         file_path = self.NewTempFile()
 
         logging.debug(
@@ -227,7 +242,7 @@ class TestDataFile(unittest.TestCase):
 
     self.assertEqual(
         correct,
-        len(CODECS_TO_VALIDATE) * len(SCHEMAS_TO_VALIDATE))
+        len(codecs_to_validate) * len(SCHEMAS_TO_VALIDATE))
 
   def testContextManager(self):
     file_path = self.NewTempFile()


Mime
View raw message