Skip to content

Commit

Permalink
Terminated fixed, sizeof raises SizeofError
Browse files Browse the repository at this point in the history
  • Loading branch information
arekbulski committed Mar 31, 2018
1 parent 2aaaa55 commit 4546be4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion construct/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -4308,7 +4308,7 @@ def _build(self, obj, stream, context, path):
return obj

def _sizeof(self, context, path):
return 0
raise SizeofError


#===============================================================================
Expand Down
13 changes: 6 additions & 7 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ def test_struct():
common(Struct(), b"", Container(), 0)
common(Struct("a"/Int16ub, "b"/Int8ub), b"\x00\x01\x02", Container(a=1,b=2), 3)
common(Struct("a"/Struct("b"/Byte)), b"\x01", Container(a=Container(b=1)), 1)
common(Struct(Const(b"\x00"), Padding(1), Pass, Terminated), bytes(2), {}, 2)
common(Struct(Const(b"\x00"), Padding(1), Pass, Terminated), bytes(2), {}, SizeofError)
assert raises(Struct("missingkey"/Byte).build, {}) == KeyError
assert raises(Struct(Bytes(this.missing)).sizeof) == SizeofError
d = Struct(Computed(7), Const(b"JPEG"), Pass, Terminated)
Expand Down Expand Up @@ -578,8 +578,8 @@ def test_error():
assert raises(("x"/Int8sb >> IfThenElse(this.x > 0, Int8sb, Error)).parse, b"\xff\x05") == ExplicitError

def test_focusedseq():
common(FocusedSeq("num", Const(b"MZ"), "num"/Byte, Terminated), b"MZ\xff", 255, 3)
common(FocusedSeq(this._.s, Const(b"MZ"), "num"/Byte, Terminated), b"MZ\xff", 255, 3, s="num")
common(FocusedSeq("num", Const(b"MZ"), "num"/Byte, Terminated), b"MZ\xff", 255, SizeofError)
common(FocusedSeq(this._.s, Const(b"MZ"), "num"/Byte, Terminated), b"MZ\xff", 255, SizeofError, s="num")

assert raises(FocusedSeq("missing", Pass).parse, b"") == UnboundLocalError
assert raises(FocusedSeq("missing", Pass).build, {}) == UnboundLocalError
Expand Down Expand Up @@ -915,11 +915,10 @@ def test_pass():
common(Pass, b"", None, 0)
common(Struct("empty"/Pass), b"", Container(empty=None), 0)

@xfail(reason="unknown cause, Bitwise was reimplemented using Transformed")
def test_terminated():
common(Terminated, b"", None, 0)
common(Struct(Terminated), b"", Container(), 0)
common(BitStruct(Terminated), b"", Container(), 0)
common(Terminated, b"", None, SizeofError)
common(Struct(Terminated), b"", Container(), SizeofError)
common(BitStruct(Terminated), b"", Container(), SizeofError)
assert raises(Terminated.parse, b"x") == TerminatedError
assert raises(Struct(Terminated).parse, b"x") == TerminatedError
assert raises(BitStruct(Terminated).parse, b"x") == TerminatedError
Expand Down

0 comments on commit 4546be4

Please sign in to comment.