Skip to content

Commit

Permalink
add 'adapters' for integration and functional testing
Browse files Browse the repository at this point in the history
  • Loading branch information
xlcnd committed Jan 19, 2015
1 parent 0a824e4 commit 91e7841
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
36 changes: 36 additions & 0 deletions isbntools/test/adapters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# flake8: noqa
# pylint: skip-file

import os

from subprocess import Popen, PIPE, STDOUT
from tempfile import NamedTemporaryFile


def run_cmd(command, input_text):
"""Run: cmd 'some input text'."""
return run_cmd_pipe(input_text)

def run_cmd_pipe(command, input_text):
"""Run: echo 'some input text' | python cmd.py."""
pipe = Popen(['python', command], stdout=PIPE, stdin=PIPE, stderr=STDOUT)
output = pipe.communicate(input=input_text)[0]
return output

def run_cmd_file(command, input_text):
"""Run: python cmd.py file."""
temp_file = NamedTemporaryFile(delete=False)
temp_file.write(input_text)
temp_file.close()
pipe = Popen(['python', command, temp_file.name], stdout=PIPE, stderr=STDOUT)
output = pipe.communicate()[0]
os.unlink(temp_file.name)
return output

def run_code(code):
"""Run: python -c 'some code'"""
pipe = Popen(['python', '-c', code], stdout=PIPE, stderr=STDOUT)
output = pipe.communicate()[0]
return output
13 changes: 10 additions & 3 deletions isbntools/test/test_sprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,25 @@

import sys

from isbnlib.dev.bouth23 import u
from isbnlib.dev.bouth23 import u, b, b2u3

from isbntools._lab import sprint

from isbntools.test.adapters import run_code

"""
nose tests
"""


def test_sprint():
def test_sprint1():
try:
sprint(u('海明威'))
except:
raise

def test_sprint2():
code = "from isbnlib.dev.bouth23 import u;from isbntools._lab import sprint;sprint(u('abc'))"
run_code(code)
assert run_code(code) == b('abc\n')


0 comments on commit 91e7841

Please sign in to comment.