def test_base_command(self): """RdpClassifier should return expected shell command.""" app = RdpClassifier() exp = ''.join([ 'cd "', getcwd(), '/"; java -Xmx1000m -jar "', self.user_rdp_jar_path, '" -q']) self.assertEqual(app.BaseCommand, exp)
def test_assign_jvm_parameters(self): """RdpCalssifier should pass alternate parameters to Java VM.""" app = RdpClassifier() app.Parameters['-Xmx'].on('75M') exp = ''.join([ 'cd "', getcwd(), '/"; java -Xmx75M -jar "', self.user_rdp_jar_path, '" -q']) self.assertEqual(app.BaseCommand, exp)
def test_change_working_dir(self): """RdpClassifier should run program in expected working directory.""" test_dir = '/tmp/RdpTest' app = RdpClassifier(WorkingDir=test_dir) exp = ''.join(['cd "', test_dir, '/"; java -Xmx1000m -jar "', self.user_rdp_jar_path, '"']) self.assertEqual(app.BaseCommand, exp) rmtree(test_dir)
def test_sample_fasta(self): """RdpClassifier should classify its own sample data correctly""" test_dir = '/tmp/RdpTest' app = RdpClassifier(WorkingDir=test_dir) _, output_fp = tempfile.mkstemp(dir=test_dir) app.Parameters['-o'].on(output_fp) results = app(StringIO(rdp_sample_fasta)) assignment_toks = results['Assignments'].readline().split('\t') self.assertEqual(assignment_toks[0], 'X67228') lineage = [x.strip('"') for x in assignment_toks[2::3]] self.assertEqual(lineage, [ 'Root', 'Bacteria', 'Proteobacteria', 'Alphaproteobacteria', 'Rhizobiales', 'Rhizobiaceae', 'Rhizobium']) rmtree(test_dir)
def test_sample_fasta(self): """RdpClassifier should classify its own sample data correctly""" test_dir = '/tmp/RdpTest' app = RdpClassifier(WorkingDir=test_dir) results = app(rdp_sample_fasta) results_file = results['StdOut'] id_line = results_file.readline() self.failUnless(id_line.startswith('>X67228')) classification_line = results_file.readline().strip() obs = parse_rdp(classification_line) exp = ['Root', 'Bacteria', 'Proteobacteria', 'Alphaproteobacteria', 'Rhizobiales', 'Rhizobiaceae', 'Rhizobium'] self.assertEqual(obs, exp) rmtree(test_dir)
def test_basecommand_property(self): """RdpClassifier BaseCommand property should use overridden method.""" app = RdpClassifier() self.assertEqual(app.BaseCommand, app._get_base_command())
def test_parameters_list(self): a = RdpClassifier() parameters = list(a.Parameters.keys()) parameters.sort() self.assertEqual(parameters, ['-Xmx', '-f', '-o', '-t'])
def test_default_java_vm_parameters(self): """RdpClassifier should store default arguments to Java VM.""" a = RdpClassifier() self.assertContains(a.Parameters, '-Xmx') self.assertEqual(a.Parameters['-Xmx'].Value, '1000m')
def test_default_positional_parameters(self): """RdpClassifier should store default positional arguments.""" a = RdpClassifier() self.assertContains(a.PositionalParameters, '-training-data') self.assertEqual(a.PositionalParameters['-training-data'].Value, '')
def test_positional_parameters_list(self): a = RdpClassifier() parameters = a.PositionalParameters.keys() parameters.sort() self.assertEqual(parameters, ['-training-data'])
def test_jvm_parameters_list(self): a = RdpClassifier() parameters = a.JvmParameters.keys() parameters.sort() self.assertEqual(parameters, ['-Xmx'])