Exemple #1
0
class TestFaultYamlParser(unittest.TestCase):
    '''
    Main test class of the Fault Yaml Parser function
    '''
    def setUp(self):
        self.parser = None
        self.fault_geometry = None

    def test_bad_input_fault_model(self):
        # Test that when Yaml is missing 'Fault_Model' atribute an error is
        # raised
        with self.assertRaises(ValueError) as ae:
            self.parser = FaultYmltoSource(BAD_INPUT_FILE)
        self.assertEqual(str(ae.exception),
                         'Fault Model not defined in input file!')

    def test_bad_geometry_input(self):
        # Tests that an unknown geomtry error is raised when not recognised
        self.parser = FaultYmltoSource(BAD_GEOMETRY_FILE)
        with self.assertRaises(ValueError) as ae:
            self.parser.read_file()
        self.assertEqual(str(ae.exception),
                         'Unrecognised or unsupported fault geometry!')

    def test_simple_fault_input(self):
        # Tests a simple fault input
        self.parser = FaultYmltoSource(SIMPLE_GEOMETRY_FILE)
        fault_model, tect_reg = self.parser.read_file()
        # Test that the area is correct and the slip rate
        self.assertAlmostEqual(fault_model.faults[0].area,
                               3851.9052498454062)
        expected_slip = [(18.0, 0.3), (20.0, 0.5), (23.0, 0.2)]
        for iloc, slip in enumerate(expected_slip):
            self.assertAlmostEqual(
                slip[0], fault_model.faults[0].slip[iloc][0])
            self.assertAlmostEqual(
                slip[1], fault_model.faults[0].slip[iloc][1])

        self.assertTrue(isinstance(fault_model.faults[0].geometry,
                                   SimpleFaultGeometry))

    def test_complex_fault_input(self):
        # Tests a complex fault input
        # Quick test - just ensure that the area and the slip rate are expected
        self.parser = FaultYmltoSource(COMPLEX_GEOMETRY_FILE)
        fault_model, tect_reg = self.parser.read_file(2.0)
        # Test that the area is correct and the slip rate
        self.assertAlmostEqual(fault_model.faults[0].area,
                               13745.614848626545)
        expected_slip = [(18.0, 0.3), (20.0, 0.5), (23.0, 0.2)]
        for iloc, slip in enumerate(expected_slip):
            self.assertAlmostEqual(
                slip[0], fault_model.faults[0].slip[iloc][0])
            self.assertAlmostEqual(
                slip[1], fault_model.faults[0].slip[iloc][1])

        self.assertTrue(isinstance(fault_model.faults[0].geometry,
                                   ComplexFaultGeometry))