def test_call_output_to_file_sorted(self): """GenericRepSetPicker.__call__ output to file sorts when requested """ fd, tmp_result_filepath = mkstemp( prefix='GenericRepSetPickerTest.test_call_output_to_file_', suffix='.txt') close(fd) app = GenericRepSetPicker(params=self.params) obs = app(self.tmp_seq_filepath, self.tmp_otu_filepath, result_path=tmp_result_filepath, sort_by='seq_id') result_file = open(tmp_result_filepath) result_file_str = result_file.read() result_file.close() # remove the result file before running the test, so in # case it fails the temp file is still cleaned up remove(tmp_result_filepath) # compare data in result file to fake expected file self.assertEqual(result_file_str, rep_seqs_result_file_sorted_exp) # confirm that nothing is returned when result_path is specified self.assertEqual(obs, None)
def test_call_log_file(self): """GenericRepSetPicker.__call__ writes log when expected """ tmp_log_filepath = get_tmp_filename(\ prefix='GenericRepSetPickerTest.test_call_output_to_file_l_',\ suffix='.txt') tmp_result_filepath = get_tmp_filename(\ prefix='GenericRepSetPickerTest.test_call_output_to_file_r_',\ suffix='.txt') app = GenericRepSetPicker(params=self.params) obs = app(self.tmp_seq_filepath, self.tmp_otu_filepath,\ result_path=tmp_result_filepath,log_path=tmp_log_filepath) log_file = open(tmp_log_filepath) log_file_str = log_file.read() log_file.close() # remove the temp files before running the test, so in # case it fails the temp file is still cleaned up remove(tmp_log_filepath) remove(tmp_result_filepath) log_file_exp = ["GenericRepSetPicker parameters:",\ 'Algorithm:first',\ "Application:None",\ 'ChoiceF:first', 'ChoiceFRequiresSeqs:False', "Result path: %s" % tmp_result_filepath,] # compare data in log file to fake expected log file for i, j in zip(log_file_str.splitlines(), log_file_exp): if not i.startswith('ChoiceF:'): #can't test, different each time self.assertEqual(i, j)
def test_call_wrapped_function(self): """GenericRepSetPicker.__call__ returns expected clusters default params""" # adapted from test_app.test_cd_hit.test_cdhit_clusters_from_seqs exp = {'0':'R27DLI_4812',\ '1':'U1PLI_7889',\ '2':'W3Cecum_4858',\ '3':'R27DLI_3243',\ } app = GenericRepSetPicker(params={'Algorithm':'most_abundant', 'ChoiceF':make_most_abundant, 'ChoiceFRequiresSeqs':True}) obs = app(self.tmp_seq_filepath, self.tmp_otu_filepath) self.assertEqual(obs, exp)
def test_call_default_params(self): """GenericRepSetPicker.__call__ returns expected clusters default params""" # adapted from test_app.test_cd_hit.test_cdhit_clusters_from_seqs exp = {'0':'R27DLI_4812',\ '1':'U1PLI_7889',\ '2':'W3Cecum_4858',\ '3':'R27DLI_3243',\ } app = GenericRepSetPicker(params={'Algorithm':'first', 'ChoiceF':first_id}) obs = app(self.tmp_seq_filepath, self.tmp_otu_filepath) self.assertEqual(obs, exp)