[ 
https://issues.apache.org/jira/browse/BEAM-5627?focusedWorklogId=152893&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-152893
 ]

ASF GitHub Bot logged work on BEAM-5627:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 09/Oct/18 19:54
            Start Date: 09/Oct/18 19:54
    Worklog Time Spent: 10m 
      Work Description: aaltay closed pull request #6610: [BEAM-5627] Fix the 
issue of using str while byte is required in a few unit tests
URL: https://github.com/apache/beam/pull/6610
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/sdks/python/apache_beam/io/filesystems_test.py 
b/sdks/python/apache_beam/io/filesystems_test.py
index 383eb40ea07..4b5cc4d0b6e 100644
--- a/sdks/python/apache_beam/io/filesystems_test.py
+++ b/sdks/python/apache_beam/io/filesystems_test.py
@@ -204,7 +204,7 @@ def test_rename_directory(self):
     path1 = os.path.join(path_t1, 'f1')
     path2 = os.path.join(path_t2, 'f1')
     with open(path1, 'a') as f:
-      f.write('Hello')
+      f.write(b'Hello')
 
     FileSystems.rename([path_t1], [path_t2])
     self.assertTrue(FileSystems.exists(path_t2))
@@ -216,7 +216,7 @@ def test_exists(self):
     path1 = os.path.join(self.tmpdir, 'f1')
     path2 = os.path.join(self.tmpdir, 'f2')
     with open(path1, 'a') as f:
-      f.write('Hello')
+      f.write(b'Hello')
     self.assertTrue(FileSystems.exists(path1))
     self.assertFalse(FileSystems.exists(path2))
 
@@ -224,7 +224,7 @@ def test_delete(self):
     path1 = os.path.join(self.tmpdir, 'f1')
 
     with open(path1, 'a') as f:
-      f.write('Hello')
+      f.write(b'Hello')
 
     self.assertTrue(FileSystems.exists(path1))
     FileSystems.delete([path1])
diff --git a/sdks/python/apache_beam/io/sources_test.py 
b/sdks/python/apache_beam/io/sources_test.py
index cba8922976e..e46321426f1 100644
--- a/sdks/python/apache_beam/io/sources_test.py
+++ b/sdks/python/apache_beam/io/sources_test.py
@@ -53,7 +53,7 @@ def read(self, range_tracker):
       for line in f:
         if not range_tracker.try_claim(current):
           return
-        yield line.rstrip('\n')
+        yield line.decode().rstrip('\n')
         current += len(line)
 
   def split(self, desired_bundle_size, start_position=None, 
stop_position=None):
@@ -83,7 +83,6 @@ def default_output_coder(self):
 
 
 class SourcesTest(unittest.TestCase):
-
   @classmethod
   def setUpClass(cls):
     # Method has been renamed in Python 3
@@ -92,7 +91,7 @@ def setUpClass(cls):
 
   def _create_temp_file(self, contents):
     with tempfile.NamedTemporaryFile(delete=False) as f:
-      f.write(contents)
+      f.write(contents.encode())
       return f.name
 
   def test_read_from_source(self):


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 152893)
    Time Spent: 1h 10m  (was: 1h)

> Several IO tests fail in Python 3  when accessing a temporary file with  
> TypeError: a bytes-like object is required, not 'str'
> ------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: BEAM-5627
>                 URL: https://issues.apache.org/jira/browse/BEAM-5627
>             Project: Beam
>          Issue Type: Sub-task
>          Components: sdk-py-core
>            Reporter: Valentyn Tymofieiev
>            Assignee: Rakesh Kumar
>            Priority: Major
>          Time Spent: 1h 10m
>  Remaining Estimate: 0h
>
> ERROR: test_split_at_fraction_exhaustive 
> (apache_beam.io.source_test_utils_test.SourceTestUtilsTest)
>  ----------------------------------------------------------------------
>  Traceback (most recent call last):
>    File 
> "/usr/local/google/home/valentyn/projects/beam/clean_head/beam/sdks/python/apache_beam/io/source_test_utils_test.py",
>  line 120, in test_split_at_fraction_exhaustive
>      source = self._create_source(data)
>    File 
> "/usr/local/google/home/valentyn/projects/beam/clean_head/beam/sdks/python/apache_beam/io/source_test_utils_test.py",
>  line 43, in _create_source
>      source = LineSource(self._create_file_with_data(data))
>    File 
> "/usr/local/google/home/valentyn/projects/beam/clean_head/beam/sdks/python/apache_beam/io/source_test_utils_test.py",
>  line 35, in _create_file_with_data
>      f.write(line + '\n')
>    File 
> "/usr/local/google/home/valentyn/projects/beam/clean_head/beam/sdks/python/target/.tox/py3/lib/python3.5/tempfile.py",
>  line 622, in func_wrapper
>      return func(*args, **kwargs)
> TypeError: a bytes-like object is required, not 'str'
> Also similar:
> ======================================================================
>  ERROR: test_file_sink_writing 
> (apache_beam.io.filebasedsink_test.TestFileBasedSink)
> ----------------------------------------------------------------------
> Traceback (most recent call last):
>    File 
> "/usr/local/google/home/valentyn/projects/beam/clean_head/beam/sdks/python/   
>        apache_beam/io/filebasedsink_test.py", line 121, in 
> test_file_sink_writing
>       init_token, writer_results = self._common_init(sink)
>     File 
> "/usr/local/google/home/valentyn/projects/beam/clean_head/beam/sdks/python/   
>        apache_beam/io/filebasedsink_test.py", line 103, in _common_init
>       writer1 = sink.open_writer(init_token, '1')
>     File 
> "/usr/local/google/home/valentyn/projects/beam/clean_head/beam/sdks/python/   
>        apache_beam/options/value_provider.py", line 133, in _f
>       return fnc(self, *args, **kwargs)
>     File 
> "/usr/local/google/home/valentyn/projects/beam/clean_head/beam/sdks/python/   
>        apache_beam/io/filebasedsink.py", line 185, in open_writer
>     return FileBasedSinkWriter(self, os.path.join(init_result, uid) + suffix)
>     File 
> "/usr/local/google/home/valentyn/projects/beam/clean_head/beam/sdks/python/   
>        apache_beam/io/filebasedsink.py", line 385, in __init__
>       self.temp_handle = self.sink.open(temp_shard_path)
>     File 
> "/usr/local/google/home/valentyn/projects/beam/clean_head/beam/sdks/python/   
>        apache_beam/io/filebasedsink_test.py", line 82, in open
>       file_handle.write('[start]')
>   TypeError: a bytes-like object is required, not 'str'



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to