-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
56 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,44 @@ | ||
|
||
from tempfile import NamedTemporaryFile | ||
|
||
from chapter10 import C10 | ||
from chapter10.computer import ComputerF3 | ||
import pytest | ||
import docopt | ||
|
||
from c10_tools.reindex import Parser | ||
from c10_tools.reindex import main | ||
|
||
|
||
def test_noargs(): | ||
with pytest.raises(docopt.DocoptExit): | ||
Parser().main([]) | ||
@pytest.fixture | ||
def args(): | ||
return { | ||
'<src>': pytest.SAMPLE, | ||
'<dst>': NamedTemporaryFile().name, | ||
'--strip': False, | ||
'--force': True, | ||
'--quiet': False, | ||
} | ||
|
||
|
||
def test_default(): | ||
path = NamedTemporaryFile().name | ||
Parser([pytest.SAMPLE, path, '-f']).main() | ||
def test_root_offsets(args): | ||
main(args) | ||
with open(args['<dst>'], 'rb') as f: | ||
packets = list(C10(f)) | ||
offsets = list(packets[-1]) | ||
assert len(offsets) == 2 | ||
for node in offsets: | ||
f.seek(node.offset) | ||
assert next(C10(f)).data_type == 0x3 | ||
|
||
|
||
def test_node_offsets(args): | ||
main(args) | ||
with open(args['<dst>'], 'rb') as f: | ||
for packet in C10(f): | ||
if packet.data_type == 0x3 and packet.index_type == 1: | ||
indices = [(index.offset, index.channel_id, index.data_type) | ||
for index in packet] | ||
break | ||
for offset, channel_id, data_type in indices: | ||
f.seek(offset) | ||
packet = next(C10(f)) | ||
assert (packet.channel_id, packet.data_type) == (channel_id, data_type) |