Ejemplo n.º 1
0
    def test_read_csv(self):
        '''
        test the read wrapper of SBtab files
        '''
        with self.assertRaises(SBtab.SBtabError):
            SBtab.read_csv('wrong_file_path', 'doc_name')

        with self.assertRaises(SBtab.SBtabError):
            SBtab.read_csv('wrong_file_path', 'doc_name', xlsx=True)

        valid_table_types = misc.extract_supported_table_types()
        for file_name in self.table_names:
            if not file_name.startswith('_'):
                sbtab = SBtab.read_csv('python/tests/tables/' + file_name,
                                       'doc_name')
                self.assertEqual(type(sbtab), SBtab.SBtabDocument)
                for sbtab in self.sbtabs:
                    self.assertIsNotNone(sbtab._get_header_row())
                    self.assertIsNotNone(sbtab.table_type)
                    self.assertIn(sbtab.table_type, valid_table_types)
                    self.assertIsNotNone(sbtab.table_name)
                    self.assertEqual(sbtab.header_row[:7], '!!SBtab')
                    self.assertIsNotNone(sbtab.header_row.find("'"))
                    self.assertEqual(sbtab.header_row.find('"'), -1)

        sbtab_xlsx = SBtab.read_csv('python/tests/tables/_transition.xlsx',
                                    'doc_name',
                                    xlsx=True)
        self.assertEqual(type(sbtab_xlsx), SBtab.SBtabDocument)

        with self.assertRaises(SBtab.SBtabError):
            sbtab_xlsx = SBtab.read_csv('python/tests/tables/_transition.xlsx',
                                        'doc_name')
Ejemplo n.º 2
0
    def check_type_validity(self, ttype, definitions_file=None):
        '''
        Checks if the given table type is supported by default.

        Parameters
        ----------
        ttype: str
            Table type to be tested.

        Returns: Bool
            Flag that indicates if the given table type is supported by default.

        '''
        try:
            supported_types = misc.extract_supported_table_types(
                definitions_file)
        except:
            raise SBtabError('The definition file could not be found to'\
                             ' establish supported table types.')

        if ttype in supported_types: return True
        else:
            raise SBtabError(
                'The table type %s is not supported. Make sure to provide a definition file that contains this table type.'
                % ttype)
            #print('The table type %s is not supported.' % ttype)
            return True
Ejemplo n.º 3
0
 def test_extract_supported_table_types(self):
     '''
     PART 2 OF 3:
     test (with examples) if the definitions file can be used to extract the supported table types
     '''
     table_types = misc.extract_supported_table_types()
     self.assertIn('Reaction', table_types)
     self.assertIn('Compound', table_types)
     self.assertIn('Quantity', table_types)
Ejemplo n.º 4
0
 def test_extract_supported_table_types(self):
     '''
     PART 2 OF 3:
     test (with examples) if the definitions file can be used to extract the supported table types
     '''
     table_types = misc.extract_supported_table_types()
     self.assertIn('Reaction', table_types)
     self.assertIn('Compound', table_types)
     self.assertIn('Quantity', table_types)
Ejemplo n.º 5
0
    def test_check_type_validity(self):
        '''
        test if the table types are checked accurately
        '''
        valid_table_types = misc.extract_supported_table_types()

        for t in valid_table_types:
            self.assertTrue(self.docs[0].check_type_validity(t))
        with self.assertRaises(SBtab.SBtabError):
            self.docs[0].check_type_validity('Rubbish')
Ejemplo n.º 6
0
 def test_check_type_validity(self):
     '''
     test if the table types are checked accurately
     '''
     valid_table_types = misc.extract_supported_table_types()
     
     for t in valid_table_types:
         self.assertTrue(self.docs[0].check_type_validity(t))
     with self.assertRaises(SBtab.SBtabError):
         self.docs[0].check_type_validity('Rubbish')
Ejemplo n.º 7
0
 def test_find_descriptions(self):
     '''
     PART 3 OF 3:
     test if the descriptions can be read from the definitions file and
     the correct table types are inherent
     '''
     sbtab_def = misc.open_definitions_file()
     table_types = misc.extract_supported_table_types()
     for tt in table_types:
         (col2description, col2link) = misc.find_descriptions(sbtab_def, tt)
         self.assertNotEqual(col2description, {})
         self.assertNotEqual(col2link, {})
         for entry in col2link:
             self.assertEqual(entry[0], '!')
             self.assertTrue(col2link[entry] == 'True' or col2link[entry] == 'False')
Ejemplo n.º 8
0
 def test_find_descriptions(self):
     '''
     PART 3 OF 3:
     test if the descriptions can be read from the definitions file and
     the correct table types are inherent
     '''
     sbtab_def = misc.open_definitions_file()
     table_types = misc.extract_supported_table_types()
     for tt in table_types:
         (col2description, col2link) = misc.find_descriptions(sbtab_def, tt)
         self.assertNotEqual(col2description, {})
         self.assertNotEqual(col2link, {})
         for entry in col2link:
             self.assertEqual(entry[0], '!')
             self.assertTrue(col2link[entry] == 'True'
                             or col2link[entry] == 'False')
Ejemplo n.º 9
0
    def test_doc_row_attributes(self):
        '''
        test if doc row attributes are read correctly
        '''
        valid_table_types = misc.extract_supported_table_types()

        for doc in self.docs:
            self.assertIsNotNone(doc.doc_row)
            self.assertIsNotNone(doc.date)
            self.assertEqual(doc.doc_row[:8], '!!!SBtab')
            self.assertIsNotNone(doc.doc_row.find("'"))
            self.assertEqual(doc.doc_row.find('"'), -1)
            self.assertNotIn(doc.doc_row, "''")
            self.assertNotIn('^M', doc.doc_row)
            self.assertNotIn('\n', doc.doc_row)
            self.assertNotIn('\r', doc.doc_row)
            self.assertIn('Date=', doc.doc_row)
Ejemplo n.º 10
0
 def test_doc_row_attributes(self):
     '''
     test if doc row attributes are read correctly
     '''
     valid_table_types = misc.extract_supported_table_types()
     
     for doc in self.docs:
         self.assertIsNotNone(doc.doc_row)
         self.assertIsNotNone(doc.date)
         self.assertEqual(doc.doc_row[:8], '!!!SBtab')
         self.assertIsNotNone(doc.doc_row.find("'"))
         self.assertEqual(doc.doc_row.find('"'), -1)
         self.assertNotIn(doc.doc_row,"''")
         self.assertNotIn('^M',doc.doc_row)
         self.assertNotIn('\n',doc.doc_row)
         self.assertNotIn('\r',doc.doc_row)
         self.assertIn('Date=', doc.doc_row)
Ejemplo n.º 11
0
    def test_header_row(self):
        '''
        test if the SBtab has a valid header row
        '''
        valid_table_types = misc.extract_supported_table_types()

        for sbtab in self.sbtabs:
            self.assertIsNotNone(sbtab._get_header_row())
            self.assertIsNotNone(sbtab.table_type)
            self.assertIn(sbtab.table_type, valid_table_types)
            self.assertIsNotNone(sbtab.table_name)
            self.assertEqual(sbtab.header_row[:7], '!!SBtab')
            self.assertIsNotNone(sbtab.header_row.find("'"))
            self.assertEqual(sbtab.header_row.find('"'), -1)
            self.assertNotIn(sbtab._get_header_row(), "''")
            self.assertNotIn('^M', sbtab.header_row)
            self.assertNotIn('\n', sbtab.header_row)
            self.assertNotIn('\r', sbtab.header_row)
            self.assertIn('TableType=', sbtab.header_row)
            self.assertIn('TableID=', sbtab.header_row)
            self.assertIn('Date=', sbtab.header_row)
Ejemplo n.º 12
0
    def check_type_validity(self, ttype):
        '''
        Checks if the given table type is supported by default.

        Parameters
        ----------
        ttype: str
            Table type to be tested.

        Returns: Bool
            Flag that indicates if the given table type is supported by default.

        '''
        try:
            supported_types = misc.extract_supported_table_types()
        except:
            raise SBtabError('The definition file could not be found to'\
                             ' establish supported table types.')
        
        if ttype in supported_types: return True
        else:
            #raise SBtabError('The table type %s is not supported.' % ttype)
            print('The table type %s is not supported.' % ttype)
            return True