Skip to content

Commit

Permalink
FIX: hanging stream identification #189
Browse files Browse the repository at this point in the history
- added simple test, with no assert, for file identification; and
- added similar for stream identification which demonstrates hang.
  • Loading branch information
carlwilson committed May 14, 2020
1 parent 53816ea commit e59b8e4
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tests/test_fido.py
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)

0 comments on commit e59b8e4

Please sign in to comment.