eerimoq / bincopy

Mangling of various file formats that conveys binary information (Motorola S-Record, Intel HEX, TI-TXT, Verilog VMEM, ELF and binary files).
MIT License
109 stars 38 forks source link

Unit test fails #12

Closed jvroutak closed 5 years ago

jvroutak commented 5 years ago

One test fails on 64-bit Windows 10 host & 32-bit Python:

C:\GIT\bincopy>git log -1
commit 2f83b6f1570cb96bb925b416b631112c0ab4283e (HEAD -> master, tag: 14.4.0, origin/master, origin/HEAD)
Author: Erik Moqvist <erik.moqvist@gmail.com>
Date:   Mon Jul 16 08:08:12 2018 +0200

    Version 14.4.0.

C:\GIT\bincopy>git status
On branch master
Your branch is up to date with 'origin/master'.

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        .project
        .pydevproject

nothing added to commit but untracked files present (use "git add" to track)

C:\GIT\bincopy>python2
Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:42:59) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> ^Z

C:\GIT\bincopy>python3
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:06:47) [MSC v.1914 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> ^Z

Tests seem to fail:

C:\GIT\bincopy>python2 setup.py test
...
======================================================================
FAIL: test_binary (tests.test_bincopy.BinCopyTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "c:\git\bincopy\tests\test_bincopy.py", line 245, in test_binary
    padding=b'\x00'), fin.read())
AssertionError: bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00:2001:20010000214601360121470136007EFE09D219012146017E17C20001FF5F16002148011979\r\n:20012000194E79234623965778239EDA3F01B2CA3F0156702B5E712B722B7321460134219F\r\n:00000001FF\r\n') != '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00:2001:20010000214601360121470136007EFE09D219012146017E17C20001FF5F16002148011979\n:20012000194E79234623965778239EDA3F01B2CA3F0156702B5E712B722B7321460134219F\n:00000001FF\n'

----------------------------------------------------------------------
Ran 61 tests in 2.170s

FAILED (failures=1)
C:\GIT\bincopy>python3 setup.py test
running test
...
======================================================================
FAIL: test_binary (tests.test_bincopy.BinCopyTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "c:\git\bincopy\tests\test_bincopy.py", line 245, in test_binary
    padding=b'\x00'), fin.read())
AssertionError: bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x[205 chars]r\n') != b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00[188 chars]FF\n'

----------------------------------------------------------------------
Ran 61 tests in 1.912s

FAILED (failures=1)
Test failed: <unittest.runner.TextTestResult run=61 errors=0 failures=1>
error: Test failed: <unittest.runner.TextTestResult run=61 errors=0 failures=1>
eerimoq commented 5 years ago

Looks like the line ending is \r\n on the left and \n on the right in the assertion. Maybe GIT automatically converts line endings on checkout, but I cannot explain why it only happend to one of the two files.

Try to download the ZIP file of the repository instead. Maybe it solves the issue.

jvroutak commented 5 years ago

Right, that indeed seems to be the issue.

bincopy is cloned with core.autocrlf=false; bincopy2 is cloned with core.autocrlf=true.

juho@DESKTOP MINGW64 ~/Documents/git
$ python -m hexdump bincopy/tests/files/binary2.bin
00000000: 3A 32 30 30 31 30 30 30  30 32 31 34 36 30 31 33  :200100002146013
00000010: 36 30 31 32 31 34 37 30  31 33 36 30 30 37 45 46  60121470136007EF
00000020: 45 30 39 44 32 31 39 30  31 32 31 34 36 30 31 37  E09D219012146017
00000030: 45 31 37 43 32 30 30 30  31 46 46 35 46 31 36 30  E17C20001FF5F160
00000040: 30 32 31 34 38 30 31 31  39 37 39 0A 3A 32 30 30  02148011979.:200
00000050: 31 32 30 30 30 31 39 34  45 37 39 32 33 34 36 32  12000194E7923462
00000060: 33 39 36 35 37 37 38 32  33 39 45 44 41 33 46 30  3965778239EDA3F0
00000070: 31 42 32 43 41 33 46 30  31 35 36 37 30 32 42 35  1B2CA3F0156702B5
00000080: 45 37 31 32 42 37 32 32  42 37 33 32 31 34 36 30  E712B722B7321460
00000090: 31 33 34 32 31 39 46 0A  3A 30 30 30 30 30 30 30  134219F.:0000000
000000A0: 31 46 46 0A                                       1FF.

juho@DESKTOP MINGW64 ~/Documents/git
$ python -m hexdump bincopy/tests/files/binary3.bin
00000000: 00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 3A  ...............:
00000010: 32 30 30 31 3A 32 30 30  31 30 30 30 30 32 31 34  2001:20010000214
00000020: 36 30 31 33 36 30 31 32  31 34 37 30 31 33 36 30  6013601214701360
00000030: 30 37 45 46 45 30 39 44  32 31 39 30 31 32 31 34  07EFE09D21901214
00000040: 36 30 31 37 45 31 37 43  32 30 30 30 31 46 46 35  6017E17C20001FF5
00000050: 46 31 36 30 30 32 31 34  38 30 31 31 39 37 39 0A  F16002148011979.
00000060: 3A 32 30 30 31 32 30 30  30 31 39 34 45 37 39 32  :20012000194E792
00000070: 33 34 36 32 33 39 36 35  37 37 38 32 33 39 45 44  34623965778239ED
00000080: 41 33 46 30 31 42 32 43  41 33 46 30 31 35 36 37  A3F01B2CA3F01567
00000090: 30 32 42 35 45 37 31 32  42 37 32 32 42 37 33 32  02B5E712B722B732
000000A0: 31 34 36 30 31 33 34 32  31 39 46 0A 3A 30 30 30  1460134219F.:000
000000B0: 30 30 30 30 31 46 46 0A                           00001FF.

juho@DESKTOP MINGW64 ~/Documents/git
$ python -m hexdump bincopy2/tests/files/binary2.bin
00000000: 3A 32 30 30 31 30 30 30  30 32 31 34 36 30 31 33  :200100002146013
00000010: 36 30 31 32 31 34 37 30  31 33 36 30 30 37 45 46  60121470136007EF
00000020: 45 30 39 44 32 31 39 30  31 32 31 34 36 30 31 37  E09D219012146017
00000030: 45 31 37 43 32 30 30 30  31 46 46 35 46 31 36 30  E17C20001FF5F160
00000040: 30 32 31 34 38 30 31 31  39 37 39 0D 0A 3A 32 30  02148011979..:20
00000050: 30 31 32 30 30 30 31 39  34 45 37 39 32 33 34 36  012000194E792346
00000060: 32 33 39 36 35 37 37 38  32 33 39 45 44 41 33 46  23965778239EDA3F
00000070: 30 31 42 32 43 41 33 46  30 31 35 36 37 30 32 42  01B2CA3F0156702B
00000080: 35 45 37 31 32 42 37 32  32 42 37 33 32 31 34 36  5E712B722B732146
00000090: 30 31 33 34 32 31 39 46  0D 0A 3A 30 30 30 30 30  0134219F..:00000
000000A0: 30 30 31 46 46 0D 0A                              001FF..

juho@DESKTOP MINGW64 ~/Documents/git
$ python -m hexdump bincopy2/tests/files/binary3.bin
00000000: 00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 3A  ...............:
00000010: 32 30 30 31 3A 32 30 30  31 30 30 30 30 32 31 34  2001:20010000214
00000020: 36 30 31 33 36 30 31 32  31 34 37 30 31 33 36 30  6013601214701360
00000030: 30 37 45 46 45 30 39 44  32 31 39 30 31 32 31 34  07EFE09D21901214
00000040: 36 30 31 37 45 31 37 43  32 30 30 30 31 46 46 35  6017E17C20001FF5
00000050: 46 31 36 30 30 32 31 34  38 30 31 31 39 37 39 0A  F16002148011979.
00000060: 3A 32 30 30 31 32 30 30  30 31 39 34 45 37 39 32  :20012000194E792
00000070: 33 34 36 32 33 39 36 35  37 37 38 32 33 39 45 44  34623965778239ED
00000080: 41 33 46 30 31 42 32 43  41 33 46 30 31 35 36 37  A3F01B2CA3F01567
00000090: 30 32 42 35 45 37 31 32  42 37 32 32 42 37 33 32  02B5E712B722B732
000000A0: 31 34 36 30 31 33 34 32  31 39 46 0A 3A 30 30 30  1460134219F.:000
000000B0: 30 30 30 30 31 46 46 0A                           00001FF.

Tests succeed for bincopy but fail with the same error for bincopy2.

Looks like .gitattributes could solve this?

eerimoq commented 5 years ago

Yes, can you add one as you can reproduce the issue?

I have never used a .gitattributes file, but I guess *.bin -text could work.

https://stackoverflow.com/questions/11162267/how-do-i-make-git-treat-a-file-as-binary

eerimoq commented 5 years ago

@jvroutak Any progress, or should I close the issue without a fix?

jvroutak commented 5 years ago

I haven't had the time to confirm the fix yet, sorry about that. I should be able to finish this next week though.

eerimoq commented 5 years ago

Ok

eerimoq commented 5 years ago

Fixed in #13