# Path: cutadapt-1.12/tests/utils.py
# def run(params, expected, inpath, inpath2=None):
# 	if type(params) is str:
# 		params = params.split()
# 	with temporary_path(expected) as tmp_fastaq:
# 		params += ['-o', tmp_fastaq ] # TODO not parallelizable
# 		params += [ datapath(inpath) ]
# 		if inpath2:
# 			params += [ datapath(inpath2) ]
# 		assert cutadapt.main(params) is None
# 		# TODO redirect standard output
# 		assert files_equal(cutpath(expected), tmp_fastaq)
# 	# TODO diff log files
# 
# def files_equal(path1, path2):
# 	return os.system("diff -u {0} {1}".format(path1, path2)) == 0
# 
# def datapath(path):
# 	return os.path.join(os.path.dirname(__file__), 'data', path)
# 
# def cutpath(path):
# 	return os.path.join(os.path.dirname(__file__), 'cut', path)
# 
# @contextmanager
# def redirect_stderr():
# 	"Send stderr to stdout. Nose doesn't capture stderr, yet."
# 	old_stderr = sys.stderr
# 	sys.stderr = sys.stdout
# 	yield
# 	sys.stderr = old_stderr
# 
# @contextmanager
# def temporary_path(name):
# 	directory = os.path.join(os.path.dirname(__file__), 'testtmp')
# 	if not os.path.isdir(directory):
# 		os.mkdir(directory)
# 	path = os.path.join(directory, name)
# 	yield path
# 	os.remove(path)


import shutil
from nose.tools import raises
from cutadapt.scripts import cutadapt
from .utils import run, files_equal, datapath, cutpath, redirect_stderr, temporary_path
# coding: utf-8
from __future__ import print_function, division, absolute_import


def run_paired(params, in1, in2, expected1, expected2):
	if type(params) is str:
		params = params.split()
	with temporary_path('tmp1-' + expected1) as p1:
		with temporary_path('tmp2-' + expected2) as p2:
			params += ['-o', p1, '-p', p2]
			params += [datapath(in1), datapath(in2)]
			assert cutadapt.main(params) is None
			assert files_equal(cutpath(expected1), p1)
			assert files_equal(cutpath(expected2), p2)


def run_interleaved(params, inpath1, inpath2=None, expected1=None, expected2=None):
	"""
	Interleaved input or output (or both)
	"""
	assert not (inpath1 and inpath2 and expected1 and expected2)
	assert not (expected2 and not expected1)
	assert not (inpath2 and not inpath1)
	if type(params) is str:
		params = params.split()
	params += ['--interleaved']

# Path: cutadapt-1.12/tests/utils.py
# def run(params, expected, inpath, inpath2=None):
# 	if type(params) is str:
# 		params = params.split()
# 	with temporary_path(expected) as tmp_fastaq:
# 		params += ['-o', tmp_fastaq ] # TODO not parallelizable
# 		params += [ datapath(inpath) ]
# 		if inpath2:
# 			params += [ datapath(inpath2) ]
# 		assert cutadapt.main(params) is None
# 		# TODO redirect standard output
# 		assert files_equal(cutpath(expected), tmp_fastaq)
# 	# TODO diff log files
# 
# def files_equal(path1, path2):
# 	return os.system("diff -u {0} {1}".format(path1, path2)) == 0
# 
# def datapath(path):
# 	return os.path.join(os.path.dirname(__file__), 'data', path)
# 
# def cutpath(path):
# 	return os.path.join(os.path.dirname(__file__), 'cut', path)
# 
# @contextmanager
# def redirect_stderr():
# 	"Send stderr to stdout. Nose doesn't capture stderr, yet."
# 	old_stderr = sys.stderr
# 	sys.stderr = sys.stdout
# 	yield
# 	sys.stderr = old_stderr
# 
# @contextmanager
# def temporary_path(name):
# 	directory = os.path.join(os.path.dirname(__file__), 'testtmp')
# 	if not os.path.isdir(directory):
# 		os.mkdir(directory)
# 	path = os.path.join(directory, name)
# 	yield path
# 	os.remove(path)


# Path: cutadapt-1.12/tests/testpaired.py
import shutil
from nose.tools import raises
from cutadapt.scripts import cutadapt
from .utils import run, files_equal, datapath, cutpath, redirect_stderr, temporary_path

# coding: utf-8
from __future__ import print_function, division, absolute_import


def run_paired(params, in1, in2, expected1, expected2):
	if type(params) is str:
		params = params.split()
	with temporary_path('tmp1-' + expected1) as p1:
		with temporary_path('tmp2-' + expected2) as p2:
			params += ['-o', p1, '-p', p2]
			params += [datapath(in1), datapath(in2)]
			assert cutadapt.main(params) is None
			assert files_equal(cutpath(expected1), p1)
			assert files_equal(cutpath(expected2), p2)


def run_interleaved(params, inpath1, inpath2=None, expected1=None, expected2=None):
	"""
	Interleaved input or output (or both)
	"""
	assert not (inpath1 and inpath2 and expected1 and expected2)
	assert not (expected2 and not expected1)
	assert not (inpath2 and not inpath1)
	if type(params) is str:
		params = params.split()
	params += ['--interleaved']

	with temporary_path('tmp1-' + expected1) as tmp1: