Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ML-3730: fix support for client running on windows OS #106

Open
wants to merge 5 commits into
base: development
Choose a base branch
from

Conversation

assaf758
Copy link
Member

@assaf758 assaf758 commented Apr 15, 2023

Fix support for client running on windows OS:

  • Always use slash ('/') as separator, regardless of OS
  • Fix KV support - use 'q' for to assure 8B encoding of long types in arrays

Tested on a windows vm by installing v3io-py private branch and running the CI test suit

@assaf758 assaf758 requested a review from gtopper April 15, 2023 23:15
@assaf758 assaf758 force-pushed the ML-3730 branch 3 times, most recently from 6bad94d to b425feb Compare April 20, 2023 22:33
@assaf758 assaf758 changed the title ML-3730: fix path joining when client OS is windows ML-3730: fix support for client running on windows OS Apr 20, 2023
@@ -266,7 +266,7 @@ def test_verifier_transport(self):

# verify some stuff from the request
self.assertEqual(request.container, container_name)
self.assertEqual(request.path, os.path.join(os.sep, container_name, 'some/path'))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really want to put this in the readme? If so, we should put the import there as well.

#
import unittest

from v3io.common.helpers import url_join
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this file should be called test_helpers.py?



class Test(unittest.TestCase):
def test_url_join(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably better make this a parameterized test, so that we can see which test cases pass and which fail.

self.assertEqual(url_join("a", "b"), "a/b") # keep suffix "/" exist/not-exist invariant
self.assertEqual(url_join("a", "b/"), "a/b/")
self.assertEqual(url_join("a", "b//"), "a/b//")
self.assertEqual(url_join("a", "b//", "/"), "a/b//") # suffix "/" count (if > 0) may change (but we don"t care)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.assertEqual(url_join("a", "b//", "/"), "a/b//") # suffix "/" count (if > 0) may change (but we don"t care)
self.assertEqual(url_join("a", "b//", "/"), "a/b//") # suffix "/" count (if > 0) may change (but we don't care)

Also, I wonder if we don't want to remove redundant slashes in any case.


for part in parts:
if part[0] != "/":
def url_join(*parts):
Copy link
Member

@gtopper gtopper Apr 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this might be clearer:

def url_join(*parts):
    slash_suffix = False
    result = ""
    for part_index, part in enumerate(parts):
        if part == "":
            continue

        if slash_suffix:
            # if slash suffix existed in prev trim slash prefix from this part
            result += part.lstrip("/")
        else:
            # add slash prefix before part if:
            # 1. slash suffix did not exist in prev part and
            # 2. slash prefix does not exist in this part and
            # 3. part is not the first
            if part[0] != "/" and part_index != 0:
                result += "/"
            result += part

        slash_suffix = part[-1] == "/"
    return result

Comment on lines +23 to +26
# add slash prefix before part if:
# 1. slash suffix did not exit in prev part
# 2. slash prefix does not exit in this part
# 3. part is not the first
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exit -> exist

Need to make it clear that all 3 points need to be true (could be read as just one of them).


class Test(unittest.TestCase):
def test_url_join(self):
self.assertEqual(url_join("a", "b"), "a/b") # add just exactly one "/" between parts
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For whaterver reason, assertEqual treats the left side as the expected and right side as the actual. Opposite of a simple assert.

@@ -24,7 +24,7 @@


def encode_list(list_value):
typecode = "l"
typecode = "q"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use a constant or a comment to communicate that this means 8 bytes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants