""" Test the file recognizer capabilities.
"""

import gzip
import os
import shutil
import socket
import sys

import nose

from grin import FileRecognizer

def empty_file(filename, open=open):
    f = open(filename, 'wb')
    f.close()

def binary_file(filename, open=open):
    f = open(filename, 'wb')
    f.write(''.join(map(chr, range(256))))
    f.close()

def text_file(filename, open=open):
    lines = ['foo\n', 'bar\n'] * 100
    lines.append('baz\n')
    lines.extend(['foo\n', 'bar\n'] * 100)
    f = open(filename, 'wb')
    f.writelines(lines)
    f.close()

def fake_gzip_file(filename, open=open):
    """ Write out a binary file that has the gzip magic header bytes, but is not
    a gzip file.
    """
    GZIP_MAGIC = '\037\213'
    f = open(filename, 'wb')
    f.write(GZIP_MAGIC)
    f.write(''.join(map(chr, range(256))))
    f.close()