Ejemplo n.º 1
0
    def test_get_properties_method():
        """
        Test get properties method in Family class

        """
        family = [
            Male(age=48),
            Female(age=45, pregnant='1'),
            Female(age=17),
            Male(age=13, sfo='1'),
            Female(age=5, kinder_garden='1')
        ]
        properties = {
            'inntekt': '1489000',
            'antall_biler': '2',
            'select_year': '2021'
        }
        for i, member in enumerate(family):
            for key, value in member.__dict__.items():
                if "_id" not in key:
                    properties.update({key[1:] + str(i): value})

        fam = Family(family, income=1489000, cars=2, select_year=2021)

        assert fam.sifo_properties() == properties
Ejemplo n.º 2
0
    def test_family_cannot_exist_without_guardianship(invalid_family):
        """
        Test that Family object cannot exist without guardianship, i.e. must have atleast one
        person over 18 years.

        """
        with pt.raises(NotPossibleError):
            family = Family(invalid_family) if isinstance(
                invalid_family, list) else Family([invalid_family])
            print(family)
Ejemplo n.º 3
0
    def setup(cls):
        """
        Executed before all tests

        """
        cls.family_members = [Male(age=39), Female(age=40)]
        cls.family = Family(cls.family_members)
Ejemplo n.º 4
0
    def test_family_members_type_are_list_constructor(invalid_arg):
        """
        Test that Family object raises TrackingError if family_members argument are invalid

        """
        with pt.raises(TrackingError):
            Family(invalid_arg, income=invalid_arg, cars=invalid_arg)
Ejemplo n.º 5
0
    def test_rules_in_family(self):
        """
        Test that rules are included in Family object

        """
        rules = [
            "non_negative_income", "non_negative_cars",
            "kindergarten_criteria", "sfo_criteria", "pregnant_criteria"
        ]
        assert Family.rules() == ", ".join(rules).replace("'", "")
        assert self.family.rules() == ", ".join(rules).replace("'", "")
Ejemplo n.º 6
0
    def setup(cls):
        """
        Executed before every test

        """
        family_members = [Male(age=45), Female(age=40)]
        cls.family = Family(family_members,
                            income=850000,
                            cars=1,
                            select_year=2021)
        cls.sifo = Sifo(cls.family)
Ejemplo n.º 7
0
    def test_arguments_gets_set_in_family_object_constructor(
            inntekt, antall_biler):
        """
        Test that valid arguments gets set into object through constructor

        """
        new_family = [Male(25), Female(24)]
        family = Family(new_family, inntekt, antall_biler, select_year=2021)

        assert family.familie_medlemmer == new_family
        assert family.inntekt == str(inntekt)
        assert family.antall_biler == str(antall_biler)
Ejemplo n.º 8
0
    def test_that_family_get_set(self):
        """
        Test that Family object gets set if passed through constructor or setter

        """
        assert self.sifo.family == self.family

        new_family = Family(
            [Female(age=40),
             Female(age=13, sfo='1'),
             Male(age=10, sfo='1')])
        self.sifo.family = new_family
        assert self.sifo.family == new_family
Ejemplo n.º 9
0
    def setup(cls):
        """
        Executed before every test

        """
        family_members = [
            Male(age=45),
            Female(age=40),
            Female(age=13, sfo='1'),
            Male(age=10, sfo='1')
        ]
        cls.family = Family(family_members, income=850000, cars=2)
        cls.sifo = Sifo(cls.family)
Ejemplo n.º 10
0
    def __init__(self, data: dict):
        """
        Constructor / Instantiate the class.

        Parameters
        ----------
        data    : dict
                  Sifo compatible dictionary with all necessary family information

        """
        self.name = self.__class__.__name__
        Assertor.assert_data_types([data], [dict])
        super().__init__(
            name=self.name,
            desc="rules: {} \\n id: Validate Family Information".format(
                Family.rules()))
        self.data = data
Ejemplo n.º 11
0
    def run(self):
        """
        method for running operation

        Returns
        -------
        out     : Family
                  Sifo compatible Family object with all necessary family information

        """
        family_members = []
        cars = None
        income = None
        select_year = None
        for key, val in self.data.items():
            if "person" in key:
                arg = {}
                gender = None
                for prop, value in val.items():
                    if "alder" in prop:
                        arg.update({"age": self.sifo_arg[value]})
                    elif "kjonn" in prop:
                        gender = Male if "Mann" in value else Female
                    elif "barnehage" in prop:
                        arg.update({"kinder_garden": self.bool_arg[value]})
                    elif "sfo" in prop:
                        arg.update({"sfo": self.sfo_arg[value]})
                    elif "student" in prop:
                        arg.update({"student": self.bool_arg[value]})
                    elif "gravid" in prop:
                        arg.update({"pregnant": self.bool_arg[value]})
                if gender and arg:
                    family_member = gender(**arg)
                    family_members.append(family_member)
            elif "brutto_arsinntekt" in key:
                income = val.replace(" kr", "").replace(" ", "")
            elif "antall_biler" in key:
                cars = val
            elif "select_year" in key:
                select_year = val
        family_income = income if income else 0
        family_num_cars = cars if cars else 0
        family = Family(family_members, family_income, family_num_cars,
                        select_year)
        return family