Skip to content

Commit

Permalink
raise parsing error when trying to open file with the wrong file id
Browse files Browse the repository at this point in the history
  • Loading branch information
stuffmatic committed Dec 3, 2018
1 parent cd30024 commit c722d89
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 0 deletions.
2 changes: 2 additions & 0 deletions fspy_blender/fspy.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ def __init__(self, project_path):
project_file = open(project_path, "rb")

file_id = unpack('<I', project_file.read(4))[0]
if 2037412710 != file_id:
raise ParsingError("Trying to import a file that is not an fSpy project")
self.project_version = unpack('<I', project_file.read(4))[0]
if self.project_version != 1:
raise ParsingError("Unsupported fSpy project file version " + str(self.project_version))
Expand Down
7 changes: 7 additions & 0 deletions test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ def test_wrong_project_version(self):
with self.assertRaises(fspy.ParsingError):
project = fspy.Project(self.project_path('invalid_project_version.fspy'))

def test_invalid_file_type(self):
"""
Opening files that are not fSpy project files should fail
"""
with self.assertRaises(fspy.ParsingError):
project = fspy.Project(self.project_path('json_export.json'))

# Helper to get the path of a test project
def project_path(self, project_name):
return os.path.join('test_data', project_name)
Expand Down
86 changes: 86 additions & 0 deletions test_data/json_export.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
{
"principalPoint": {
"x": 0,
"y": 0
},
"viewTransform": {
"rows": [
[
-0.8432786760114586,
0.0008594611278942136,
-0.5374758933300462,
0.3346571584818884
],
[
-0.0005363911022935677,
0.9999968777735306,
0.002440640853491923,
-0.9315262352851599
],
[
0.537476312844526,
0.0023464376744316683,
-0.8432755820971535,
-4.120414307919244
],
[
0,
0,
0,
1
]
]
},
"cameraTransform": {
"rows": [
[
-0.8432786760114587,
-0.000536391102293568,
0.5374763128445262,
2.4963346727504696
],
[
0.0008594611278942138,
0.9999968777735309,
0.0023464376744316688,
0.9409039973967737
],
[
-0.5374758933300462,
0.002440640853491923,
-0.8432755820971537,
-3.292501097791757
],
[
0,
0,
0,
1
]
]
},
"horizontalFieldOfView": 1.5479845321227295,
"verticalFieldOfView": 1.1518580723726943,
"vanishingPoints": [
{
"x": 1.6051650133994935,
"y": 0.001021010320067342
},
{
"x": -0.652074716204382,
"y": 0.0029610261811691915
},
{
"x": -0.3747357368992343,
"y": -436.0110710388304
}
],
"vanishingPointAxes": [
"xNegative",
"zPositive",
"yPositive"
],
"relativeFocalLength": 1.0230759978297743,
"imageWidth": 1439,
"imageHeight": 956
}

0 comments on commit c722d89

Please sign in to comment.