#!/usr/bin/env python

# Copyright (C) 2011-2012 CRS4.
#
# This file is part of Seal.
#
# Seal is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# Seal is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License along
# with Seal.  If not, see <http://www.gnu.org/licenses/>.

#########################################################
# You need a working Hadoop cluster to use this.
#########################################################


import site
import os
import sys
import unittest

IntegrationTestDir = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", ".."))
site.addsitedir(IntegrationTestDir)

from seal_integration_test import SealIntegrationTest
import bl.lib.tools.hadut as hadut

class TestSimpleDemux(SealIntegrationTest):
	def __init__(self):
		super(TestSimpleDemux, self).__init__( os.path.realpath(os.path.dirname(__file__)) )

	def setup(self):
		super(TestSimpleDemux, self).setup()
		hadut.dfs("-put", os.path.join(self.test_dir, "sample_sheet1.csv"), self.make_hdfs_test_path())


	def process_output(self):
		if not os.path.isdir( os.path.join(self.output_dir, "csct_007107") ):
			raise AssertionError("sample directory doesn't exist")
		different = self.sorted_output_different( self.make_local_expected_output_path() , os.path.join(self.output_dir, "csct_007107"))
		self.show_test_msg( not different )
		self.rm_output_dir()
		return not different

	def run_program(self, hdfs_input, hdfs_output):
		hadut.run_class_e("it.crs4.seal.demux.Demux", self.jar, args_list=["--sample-sheet", os.path.join(self.make_hdfs_test_path(), "sample_sheet1.csv"), hdfs_input, hdfs_output])

if __name__ == '__main__':
	success = TestSimpleDemux().test_method()
	sys.exit( 0 if success else 1 )
