Skip to content

Commit

Permalink
Adds a MockCorpus#write_txt() method.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmcclure committed Feb 26, 2015
1 parent 90c3efc commit ea00697
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
27 changes: 23 additions & 4 deletions osp/corpus/test/mocks/corpus.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,10 @@ def add_file(self, segment, content, ftype='txt'):
Args:
segment (str): The segment name.
content (str): The file content.
fname (str): The file name.
ftype (str): The file type.
"""

# Get the file cheksum.
# Get the file checksum.
sha1 = hashlib.sha1()
sha1.update(content.encode('utf8'))
name = sha1.hexdigest()
Expand All @@ -61,10 +60,30 @@ def add_file(self, segment, content, ftype='txt'):
return write_file(path, content)


def write_txt(self, path, content):

"""
Write a .txt file.
Args:
path (str): The file path.
content (str): The file content.
Returns:
file: A handle on the new file.
"""

fh = open(path, 'w+')
fh.write(content)
fh.close()

return open(path, 'rb')


def write_pdf(self, path, content):

"""
Add a PDF file.
Write a .pdf file.
Args:
path (str): The file path.
Expand All @@ -84,7 +103,7 @@ def write_pdf(self, path, content):
def write_docx(self, path, content):

"""
Add a .docx file.
Write a .docx file.
Args:
path (str): The file path.
Expand Down
1 change: 1 addition & 0 deletions test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test

0 comments on commit ea00697

Please sign in to comment.