hauntsaninja / pyp

Easily run Python at the shell! Magical, but never mysterious.
MIT License
1.41k stars 39 forks source link

Count bytes in `wc -c` example #27

Open Bobronium opened 2 years ago

Bobronium commented 2 years ago
$ echo šŸ | wc -c
       5

$ echo šŸ | pyp 'len(stdin.read())'

2

$ echo šŸ | pyp 'len(stdin.read().encode())'

5
Bobronium commented 2 years ago

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 :)

Bobronium commented 2 years ago

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 on ī‚  patch-1 (.venv) 
$ echo "1\nšŸ\n2\n3" | pyp "sorted(lines)"
1
2
3
šŸ
hauntsaninja commented 2 years ago

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 commented 2 years ago

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)