Skip to content

Commit 37a45d2

Browse files
authored
Merge pull request #57 from ArcanaFramework/extra-testing
added binary testing formats
2 parents 51bde1b + 9f34271 commit 37a45d2

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

fileformats/core/fileset.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,17 +137,14 @@ def _validate_properties(self):
137137
getattr(self, check)()
138138

139139
def __eq__(self, other) -> bool:
140-
return (
141-
isinstance(other, FileSet)
142-
and self.mime_like == other.mime_like
143-
and self.fspaths == other.fspaths
144-
)
140+
return type(self) is type(other) and self.fspaths == other.fspaths
145141

146142
def __ne__(self, other) -> bool:
147143
return not self.__eq__(other)
148144

149145
def __hash__(self) -> int:
150-
return hash((self.mime_like, self.fspaths))
146+
tp = type(self)
147+
return hash((tp.__module__, tp.__name__, self.fspaths))
151148

152149
def __repr__(self) -> str:
153150
return f"{self.type_name}('" + "', '".join(str(p) for p in self.fspaths) + "')"

fileformats/testing/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
MyFormatGz,
99
MyFormatGzX,
1010
MyFormatX,
11+
MyBinaryFormat,
12+
MyHeader,
13+
MyBinaryFormatX,
14+
MyOtherBinaryFormatX,
1115
YourFormat,
1216
SeparateHeader,
1317
ImageWithHeader,

fileformats/testing/headers.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from fileformats.generic import File
22
from fileformats.application import Json
3-
from fileformats.core.mixin import WithSideCars, WithSeparateHeader
3+
from fileformats.core.mixin import WithSideCars, WithSeparateHeader, WithMagicNumber
44

55

66
class YFile(File):
@@ -36,6 +36,25 @@ class MyFormatX(WithSideCars, MyFormat):
3636
side_car_types = (Json,)
3737

3838

39+
class MyBinaryFormat(WithMagicNumber, File):
40+
ext = ".my"
41+
magic_number = b"MYFORMAT"
42+
43+
44+
class MyHeader(File):
45+
ext = ".myhdr"
46+
47+
48+
class MyBinaryFormatX(WithSeparateHeader, MyFormat):
49+
header_type = MyHeader
50+
51+
52+
class MyOtherBinaryFormatX(WithMagicNumber, WithSeparateHeader, File):
53+
magic_number = b"MYFORMAT"
54+
ext = ".my"
55+
header_type = MyHeader
56+
57+
3958
class YourFormat(File):
4059

4160
ext = ".yr"

0 commit comments

Comments
 (0)