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

Count bytes in wc -c example #27

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

Bobronium
Copy link

$ echo 🐍 | wc -c
       5

$ echo 🐍 | pyp 'len(stdin.read())'

2

$ echo 🐍 | pyp 'len(stdin.read().encode())'

5

```shell
$ echo 🐍 | wc -c
       5

$ echo 🐍 | pyp 'len(stdin.read())'

2

$ echo 🐍 | pyp 'len(stdin.read().encode())'

5
```
Copy link
Owner

@hauntsaninja hauntsaninja left a comment

Choose a reason for hiding this comment

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

Thanks for spotting this!

Technically, I think stdin.buffer.read() would be a little more accurate, since IIRC stdin isn't guaranteed to be UTF-8.
Also, would you mind making the corresponding change here as well?

example_cmd="wc -c | tr -d ' '", pyp_cmd="pyp 'len(stdin.read())'", input=example

@Bobronium
Copy link
Author

Oh, I forgot to post the issue that answers why I didn't propose stdin.buffer.read()...

Probably should've opened it in the first place :)

Emoji represents non-ascii input.
This should make tests pass, but I still haven't cloned the project to run any linters, etc.
@Bobronium Bobronium marked this pull request as draft July 29, 2022 09:20
@Bobronium
Copy link
Author

Bobronium commented Jul 30, 2022

Interesting. Tests are failing because of the difference between sort on macOS and Ubuntu.

How should we handle this, @hauntsaninja?

On Ubuntu:

$ echo "1\n🐍\n2\n3" | sort
🐍
1
2
3

On macOS:

$ echo "1\n🐍\n2\n3" | sort
1
2
3
🐍

With pyp (python sort):

~/dev/contrib/pyp onpatch-1 (.venv) 
$ echo "1\n🐍\n2\n3" | pyp "sorted(lines)"
1
2
3
🐍

@hauntsaninja
Copy link
Owner

Oh, interesting. This kind of thing is why I like pyp ;-)

Maybe we just remove the emoji from the tests. It doesn't really test the behaviour of pyp itself. The commands in the README are only approximately "like" the standard shell commands, so we don't need to have tests that enforce that they super faithfully match the standard shell commands.

@Bobronium
Copy link
Author

Ok, I've seen your comment way too late :)

I woke up with an idea how we can deal with it, keeping emoji (example of UTF-8 input) and shining the light on potential differences between platforms.

Basically, I moved arguments from individual calls to compare_command into parametrize cases, which to threat each case individually and then xfailed sort with emoji (leaving one without emoji intact)

@Bobronium Bobronium marked this pull request as ready for review July 30, 2022 11:25
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