import warnings
from unittest import TestCase
from molecupy import exceptions
from molecupy.atomic import CovalentBond, Atom

class BondTest(TestCase):

    def check_valid_covalent_bond(self, covalent_bond):
        self.assertIsInstance(covalent_bond, CovalentBond)
        self.assertIsInstance(covalent_bond.atoms, set)
        self.assertEqual(len(covalent_bond.atoms), 2)
        for atom in covalent_bond.atoms:
            self.assertIsInstance(atom, Atom)
        self.assertRegex(
         str(covalent_bond),
         r"<CovalentBond \([a-zA-Z]{1,2}-[a-zA-Z]{1,2}\)>"
        )



class BondCreationTests(BondTest):

    def test_can_create_covalent_bond(self):
        atom1 = Atom(1.0, 1.0, 1.0, "H")
        atom2 = Atom(1.0, 1.0, 2.0, "H")
        covalent_bond = CovalentBond(atom1, atom2)
        self.check_valid_covalent_bond(covalent_bond)


    def test_can_only_covalently_bond_atoms(self):
        atom1 = Atom(1.0, 1.0, 1.0, "H")
        atom2 = "Hydrogen atom"
        with self.assertRaises(TypeError):
            covalent_bond = CovalentBond(atom1, atom2)


    def test_warning_on_ludicrous_bond_length(self):
        atom1 = Atom(1.0, 1.0, 1.0, "H")
        atom2 = Atom(1.0, 1.0, 10.0, "H")
        with warnings.catch_warnings(record=True) as warnings_given:
            covalent_bond = CovalentBond(atom1, atom2)
            self.assertEqual(len(warnings_given), 1)
            self.assertEqual(
             warnings_given[0].category,
             exceptions.LongBondWarning
            )



class BondBehaviorTests(BondTest):

    def test_can_get_bond_length(self):
        atom1 = Atom(-0.791, 64.789, 30.59, "O")
        atom2 = Atom(5.132, 63.307, 56.785, "C")
        covalent_bond = CovalentBond(atom1, atom2)
        self.assertEqual(
         covalent_bond.get_bond_length(),
         atom1.distance_to(atom2)
        )

@@ -1,20 +1,4 @@
-import warnings%0A
 from
@@ -1216,62 +1216,52 @@
 ith 
-warnings.catch_warnings(record=True) as warnings_given
+self.assertWarns(exceptions.LongBondWarning)
 :%0A  
@@ -1317,185 +1317,8 @@
 m2)%0A
-            self.assertEqual(len(warnings_given), 1)%0A            self.assertEqual(%0A             warnings_given%5B0%5D.category,%0A             exceptions.LongBondWarning%0A            )
 %0A%0A%0A%0A
@@ -1418,33 +1418,25 @@
 tom(
--0.791, 64.789, 30.59, %22O
+1.0, 1.0, 1.0, %22H
 %22)%0A 
@@ -1459,33 +1459,25 @@
 tom(
-5.132, 63.307, 56.785, %22C
+1.0, 1.0, 2.0, %22H
 %22)%0A 

Remove superfulous warning in test