<commit_before><commit_msg>tests/source/rupture: tested rupture and prob.rupture objects creation<commit_after>import unittest

from nhe import const
from nhe.common.geo import Point
from nhe.common.nodalplane import NodalPlane
from nhe.common.tom import PoissonTOM
from nhe.surface.planar import PlanarSurface
from nhe.source.base import Rupture, ProbabilisticRupture, SourceError


class RuptureCreationTestCase(unittest.TestCase):
    def make_rupture(self, rupture_class, **kwargs):
        default_arguments = {
            'mag': 5.5,
            'nodal_plane': NodalPlane(1, 2, 3),
            'tectonic_region_type': const.TRT.STABLE_CONTINENTAL,
            'hypocenter': Point(5, 6, 7),
            'surface': PlanarSurface(
                Point(0, 0, 1), Point(1, 0, 1),
                Point(1, 0, 2), Point(0, 0, 2)
            )
        }
        default_arguments.update(kwargs)
        kwargs = default_arguments
        rupture = rupture_class(**kwargs)
        for key in kwargs:
            self.assertIs(getattr(rupture, key), kwargs[key])

    def assert_failed_creation(self, rupture_class, exc, msg, **kwargs):
        with self.assertRaises(exc) as ae:
            self.make_rupture(rupture_class, **kwargs)
        self.assertEqual(ae.exception.message, msg)

    def test_wrong_trt(self):
        self.assert_failed_creation(Rupture, SourceError,
            "unknown tectonic region type 'Swamp'",
            tectonic_region_type='Swamp'
        )

    def test_negative_magnitude(self):
        self.assert_failed_creation(Rupture, SourceError,
            'magnitude must be positive',
            mag=-1
        )

    def test_zero_magnitude(self):
        self.assert_failed_creation(Rupture, SourceError,
            'magnitude must be positive',
            mag=0
        )

    def test_hypocenter_in_the_air(self):
        self.assert_failed_creation(Rupture, SourceError,
            'rupture hypocenter must have positive depth',
            hypocenter=Point(0, 1, -0.1)
        )

    def test_probabilistic_rupture_negative_occurrence_rate(self):
        self.assert_failed_creation(ProbabilisticRupture, SourceError,
            'occurrence rate must be positive',
            occurrence_rate=-1, temporal_occurrence_model=PoissonTOM(10)
        )

    def test_probabilistic_rupture_zero_occurrence_rate(self):
        self.assert_failed_creation(ProbabilisticRupture, SourceError,
            'occurrence rate must be positive',
            occurrence_rate=0, temporal_occurrence_model=PoissonTOM(10)
        )

{'fraction_non_alphanumeric': 0.08724569640062597, 'fraction_numerical': 0.012519561815336464, 'mean_word_length': 2.7769571639586412, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4305626', 'n_tokens_mistral': 822, 'n_tokens_neox': 764, 'n_words': 156}