コード例 #1
0
ファイル: dbhandler_test.py プロジェクト: pawelld/PyDesc
    def test_is_id_valid(self):
        test(self.cls.is_id_valid)

        for i in self.valid_ids:
            self.assertTrue(self.handler.is_id_valid(i), "Id %s should be valid." % i)

        for i in self.invalid_ids:
            self.assertFalse(self.handler.is_id_valid(i), "Id %s should be invalid." % i)
コード例 #2
0
ファイル: dbhandler_test.py プロジェクト: pawelld/PyDesc
    def test_get_file_url(self):
        test(self.cls.get_file_url)

        for i in self.valid_ids:
            loc = self.handler.get_file_url(i)
            self.assertTrue(loc.startswith(ConfigManager.dbhandler.cachedir))

        for i in self.invalid_ids + self.nonexistent_ids:
            self.assertRaises(dbhandler.InvalidID, self.handler.get_file_url, i)
コード例 #3
0
ファイル: dbhandler_test.py プロジェクト: pawelld/PyDesc
    def setUp(self):
        self.handler = self.cls()

        test(self.cls)
        test(self.cls.__init__)
        try:
            notest(self.cls.is_file_valid)
        except AttributeError:
            pass
コード例 #4
0
ファイル: contacts_test.py プロジェクト: pawelld/PyDesc
def load_tests(loader, standard_tests, pattern):
    """ Add tests created by make_* functions for all structures. Returns a complete TestSuite. """

    structures = [
        '1asz', '1gax', '1no5', '1pxq', '2dlc', '2lp2', '3ftk', '3g88', '3lgb',
        '3m6x', '3npn', '3tk0', '3umy'
    ]

    if fast:
        structures = ['3npn', '1no5']

    def is_non_abstract_crit(c):
        if isinstance(
                c, type) and c.__module__ == 'pydesc.contacts' and issubclass(
                    c, contacts.ContactCriterion) and len(
                        c.__abstractmethods__) == 0:
            aspec = inspect.getargspec(c.__init__)
            if len(aspec.args
                   ) == 1 and aspec.varargs is None and aspec.keywords is None:
                return True

        return False

    crit_classes = filter(is_non_abstract_crit, contacts.__dict__.values())

    basic = unittest.TestSuite()

    for name in structures:
        for crit in crit_classes:
            basic.addTests(
                loader.loadTestsFromTestCase(make_contactbasictest(name,
                                                                   crit)))
        basic.addTests(
            loader.loadTestsFromTestCase(
                make_contactbasictest(name, contacts.CaCbxContact)))
        basic.addTests(loader.loadTestsFromTestCase(make_desctest(name)))
    test(contacts.CaCbxSubtractionCriterion)
    test(contacts.CaCbxSubtractionCriterion.__init__)
    test(contacts.CaCbxSubtractionCriterion.is_in_contact)
    # TO these are tested during tests added above while CaCbxContact finction calls CaCbxSubtractionCriterion methods
    test(contacts.VectorDistanceCriterion)
    test(contacts.VectorDistanceCriterion.__init__)
    # TO tested for subclass

    basic.addTests(
        loader.loadTestsFromTestCase(
            make_combcontactbasictest(contacts.ContactsAlternative)))
    basic.addTests(
        loader.loadTestsFromTestCase(
            make_combcontactbasictest(contacts.ContactsConjunction)))

    standard_tests.addTests(basic)

    return standard_tests
コード例 #5
0
ファイル: dbhandler_test.py プロジェクト: pawelld/PyDesc
    def test_download_file(self):
        test(self.cls.download_file)

        for (i, ref) in zip(self.valid_ids, self.reference_files):
            self.handler.download_file(i)
            dwnld = self.handler.get_file_location(i)
            with open(dwnld, 'r') as f:
                buf1 = f.read()

            with open(ref, 'r') as f:
                buf2 = f.read()

            self.assertEqual(buf1, buf2, "Files %s and %s differ." % (dwnld, ref))

            if fast:
                break

        for i in self.invalid_ids:
            self.assertRaises(dbhandler.InvalidID, self.handler.download_file, i)
コード例 #6
0
ファイル: dbhandler_test.py プロジェクト: pawelld/PyDesc
    def test_get_file(self):
        test(self.cls.get_file)

        for (i, ref) in zip(self.valid_ids, self.reference_files):

            dwnld = self.handler.get_file_location(i)
            with open(ref, 'r') as f:
                buf2 = f.read()

            buf1 = self.handler.get_file(i, 1).read()
            self.assertEqual(buf1, buf2, "Files %s and %s differ." % (dwnld, ref))

            buf1 = self.handler.get_file(i, 2).read()
            self.assertEqual(buf1, buf2, "Files %s and %s differ." % (dwnld, ref))

            os.remove(dwnld)

            self.assertRaises(Exception, self.handler.get_file, i, 2)

            buf1 = self.handler.get_file(i, 0).read()
            self.assertEqual(buf1, buf2, "Files %s and %s differ." % (dwnld, ref))

            os.remove(dwnld)
            with open(dwnld, 'w') as f:
                f.write('crap')

            buf1 = self.handler.get_file(i, 0).read()
            self.assertEqual(buf1, 'crap', "Files %s and %s differ." % (dwnld, ref))

            buf1 = self.handler.get_file(i, 2).read()
            self.assertEqual(buf1, 'crap', "Files %s and %s differ." % (dwnld, ref))

            buf1 = self.handler.get_file(i, 1).read()
            self.assertEqual(buf1, buf2, "Files %s and %s differ." % (dwnld, ref))

            if fast:
                break
コード例 #7
0
ファイル: contacts_test.py プロジェクト: pawelld/PyDesc
import pydesc.contacts as contacts
import pydesc.config as config
import pydesc.numberconverter as numberconverter
import tests
from pydesc.warnexcept import WrongMonomerType

config.ConfigManager.warnings_and_exceptions.class_filters.set(
    "LocalCopyAccess", "ignore")

syntax_check.module = contacts

fast = False

TestSyntax = syntax_check.module_syntax()

test(contacts.ContactCriterion)
test(contacts.DihedralAngleCriterion)
test(contacts.DihedralAngleCriterion.__init__)
test(contacts.DihedralAngleCriterion.is_in_contact)
test(contacts.HorizontalBisectorDistanceCriterion)
test(contacts.HorizontalBisectorDistanceCriterion.__init__)
test(contacts.HorizontalBisectorDistanceCriterion.is_in_contact)
test(contacts.PointsDistanceCriterion)
test(contacts.PointsDistanceCriterion.__init__)
test(contacts.SetDistanceCriterion)
test(contacts.SetDistanceCriterion.__init__)
test(contacts.SetDistanceCriterion.is_in_contact)
test(contacts.VerticalBisectorDistanceCriterion)
test(contacts.VerticalBisectorDistanceCriterion.__init__)
test(contacts.VerticalBisectorDistanceCriterion.is_in_contact)
test(contacts.CombinedContact)