예제 #1
0
    def test_wrapping(self):
        ''' Verifica se retorna o dataset apenas com o wrapping '''
        model = BaseModel()

        options = {
            **{
                "categorias": [
                    'nm_indicador', 'nu_competencia', 'vl_indicador', 'lat_mun', 'long_mun'
                ],
                "pivot": None
            }, **COMMON_OPTIONS
        }

        result = "".join(model.wrap_result(SAMPLE_DATAFRAME.copy(), options).split())

        str_expected = COMMON_EXPECTED_RESPONSE_STRING.format(
            """
                "nm_indicador": "Ficticio",
                "nu_competencia": 2099,
                "vl_indicador": 1.0
            },
            {
                "nm_indicador": "Ficticio",
                "nu_competencia": 2047,
                "vl_indicador": 0.5
            """
        )
        expected = "".join(str_expected.split())

        self.assertEqual(result, expected)
예제 #2
0
 def test_get_collection_from_invalid_type(self):
     ''' Test if the method returns None if an invalid type is passed '''
     self.assertEqual(
         BaseModel.get_collection_from_type(
             SAMPLE_DATAFRAME.copy(),
             'invalid'
         ),
         None
     )
예제 #3
0
 def test_get_collection_from_missing_type(self):
     ''' Test if the method returns None if no type is passed '''
     self.assertEqual(
         BaseModel.get_collection_from_type(
             SAMPLE_DATAFRAME.copy(),
             None
         ),
         None
     )
예제 #4
0
 def test_get_collection_from_type_first_occurence(self):
     ''' Test if the method returns the first item '''
     self.assertEqual(
         BaseModel.get_collection_from_type(
             SAMPLE_DATAFRAME.copy(),
             "first_occurence"
         ).to_dict(),
         {"index": 0, "col_1": "d", "col_2": 3, "col_3": 3}
     )
예제 #5
0
 def test_get_collection_from_type_max(self):
     ''' Test if the method returns the item with maximum value in colum '''
     self.assertEqual(
         BaseModel.get_collection_from_type(
             SAMPLE_DATAFRAME.copy(),
             "max",
             "col_2"
         ).to_dict(),
         {"col_1": "d", "col_2": 3, "col_3": 3}
     )
예제 #6
0
 def test_get_collection_from_type_from_invalid_id(self):
     ''' Test if the method returns the item with the passed string id '''
     self.assertRaises(
         ValueError,
         BaseModel.get_collection_from_type,
         SAMPLE_DATAFRAME.copy(),
         "from_id",
         "col_1",
         'a'
     )
예제 #7
0
 def test_get_collection_from_type_from_id(self):
     ''' Test if the method returns the item with the passed numeric id '''
     self.assertEqual(
         BaseModel.get_collection_from_type(
             SAMPLE_DATAFRAME.copy(),
             "from_id",
             "col_2",
             2
         ).to_dict(),
         {"col_1": "b", "col_2": 2, "col_3": 2}
     )
 def test_apply_coefficients(self):
     ''' Test if custom coefficients are applied correctly to a dataset '''
     self.assertEqual(
         TemplateHelper.apply_coefficient(
             'col_2-2-test,col_3-3-term',
             {"dataset": SAMPLE_DATAFRAME.copy()}
         )["dataset"].to_dict(),
         {
             'col_1': {0: 'd', 1: 'b', 2: 'a', 3: 'c'},
             'col_2': {0: 6.0, 1: 4.0, 2: 2.0, 3: 0.0},
             'col_3': {0: 9.0, 1: 6.0, 2: 3.0, 3: 0.0}
         }
     )
예제 #9
0
 def test_build_derivatives_nodata(self):
     ''' Test the derivate objects is added with no_data flag '''
     options = {'cd_analysis_unit': 99}
     rules = {
         "instances": [{"name": "inst_1", 'type': 'from_id', 'named_prop': 'col_2'}]
     }
     sources = {"dataset": SAMPLE_DATAFRAME.copy()}
     (der_data, der_anynodata) = BaseModel.build_derivatives(
         rules,
         options,
         sources,
         {}
     )
     self.assertEqual(
         der_data["inst_1"],
         None
     )
     self.assertEqual(der_anynodata, True)
예제 #10
0
 def test_build_derivatives(self):
     ''' Test if derivate object is added to the collection '''
     options = {'cd_analysis_unit': 2}
     rules = {
         "instances": [{"name": "inst_1", 'type': 'max', 'named_prop': 'col_2'}]
     }
     sources = {"dataset": SAMPLE_DATAFRAME.copy()}
     (der_data, der_anynodata) = BaseModel.build_derivatives(
         rules,
         options,
         sources,
         {}
     )
     self.assertEqual(
         der_data["inst_1"].to_dict(),
         {"col_1": "d", "col_2": 3, "col_3": 3}
     )
     self.assertEqual(der_anynodata, False)