-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FIX: hanging stream identification #189
- added simple test, with no assert, for file identification; and - added similar for stream identification which demonstrates hang.
- Loading branch information
1 parent
53816ea
commit e59b8e4
Showing
1 changed file
with
37 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,50 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
from __future__ import print_function | ||
|
||
import io | ||
import tempfile | ||
from time import sleep | ||
|
||
from fido import fido | ||
from fido.fido import PerfTimer | ||
|
||
# Magic number for fmt/1000. | ||
MAGIC = b"\x5A\x58\x54\x61\x70\x65\x21\x1A\x01" | ||
|
||
def test_perf_timer(): | ||
timer = PerfTimer() | ||
sleep(3.6) | ||
duration = timer.duration() | ||
assert duration > 0 | ||
|
||
def test_file_identification(): | ||
"""Reference for Fido-based format identification | ||
1. Create a byte-stream with a known magic number and serialise to tempfile. | ||
2. Call identify_file(...) to identify the file against Fido's known formats. | ||
""" | ||
# Create a temporary file on the host operating system. | ||
tmp = tempfile.mkstemp() | ||
tmp_file = tmp[1] | ||
|
||
# Write to the file our known magic-number. | ||
with open(tmp_file, "wb") as new_file: | ||
new_file.write(MAGIC) | ||
|
||
# Create a Fido instance and call identify_file. The identify_file function | ||
# will create and manage a file for itself. | ||
f = fido.Fido() | ||
f.identify_file(tmp_file) | ||
|
||
def test_stream_identification(): | ||
"""Reference for Fido-based format identification | ||
1. Create a byte-stream with a known magic number. | ||
2. Call identify_stream(...) to identify the file against Fido's known formats. | ||
""" | ||
# Create the stream object with the known magic-number. | ||
fstream = io.BytesIO(MAGIC) | ||
# Create a Fido instance and call identify_stream. The identify_stream function | ||
# will work on the stream as-is. This could be an open file handle that the | ||
# caller is managing for itself. | ||
f = fido.Fido() | ||
f.identify_stream(fstream, "filename to display", extension=False) |