def test_stratigraphy(self, mock_skippopup, mock_messagebar):
        """
        :param mock_skippopup:
        :param mock_messagebar:
        :return:
        """
        db_utils.sql_alter_db('''INSERT INTO obs_points (obsid, h_gs, geometry) VALUES ('1', 5, ST_GeomFromText('POINT(633466 711659)', 3006))''')
        db_utils.sql_alter_db('''INSERT INTO obs_points (obsid, h_gs, geometry) VALUES ('2', 10, ST_GeomFromText('POINT(6720727 016568)', 3006))''')
        db_utils.sql_alter_db('''INSERT INTO obs_points (obsid, h_gs, geometry) VALUES ('3', 20, ST_GeomFromText('POINT(6720728 016569)', 3006))''')
        db_utils.sql_alter_db('''INSERT INTO stratigraphy (obsid, stratid, depthtop, depthbot, geology, geoshort, capacity, development) VALUES ('1', 1, 0, 1, 'sand', 'sand', '3', 'j')''')
        db_utils.sql_alter_db('''INSERT INTO stratigraphy (obsid, stratid, depthtop, depthbot, geology, geoshort, capacity, development) VALUES ('1', 2, 1, 4.5, 'morän', 'morän', '3', 'j')''')

        self.create_and_select_vlayer()

        #print(str(self.vlayer.isValid()))
        #print(str(db_utils.sql_load_fr_db('select * from obs_points')))
        #print(str(db_utils.sql_load_fr_db('select * from stratigraphy')))
        dlg = Stratigraphy(self.iface, self.vlayer, self.ms.settingsdict)
        #print(str(mock_messagebar.mock_calls))
        #print(str(mock_skippopup.mock_calls))
        dlg.showSurvey()
        test = utils.anything_to_string_representation(dlg.data)
        test_survey = utils.anything_to_string_representation(repr(dlg.data['1']))
        test_strata = utils.anything_to_string_representation(utils.returnunicode(dlg.data['1'].strata, keep_containers=True))

        assert len(mock_skippopup.mock_calls) == 0
        print(str(mock_messagebar.mock_calls))
        assert len(mock_messagebar.mock_calls) == 0
        assert test == """{"1": SURVEY('1', 5.000000, '<QgsPointXY: POINT(633466 711659)>')}"""
        assert test_survey == '''"SURVEY('1', 5.000000, '<QgsPointXY: POINT(633466 711659)>')"'''
        print("test_strata: " + test_strata)
        assert test_strata == '''["strata(1, '3', 'sand', 'sand', 0.000000-1.000000)", "strata(2, '3', 'morän', 'moran', 1.000000-4.500000)"]'''
예제 #2
0
    def test_stratigraphy(self, mock_skippopup, mock_messagebar):
        """
        :param mock_skippopup:
        :param mock_messagebar:
        :return:
        """
        db_utils.sql_alter_db(
            '''INSERT INTO obs_points (obsid, h_gs, geometry) VALUES ('1', 5, ST_GeomFromText('POINT(633466 711659)', 3006))'''
        )
        db_utils.sql_alter_db(
            '''INSERT INTO obs_points (obsid, h_gs, geometry) VALUES ('2', 10, ST_GeomFromText('POINT(6720727 016568)', 3006))'''
        )
        db_utils.sql_alter_db(
            '''INSERT INTO obs_points (obsid, h_gs, geometry) VALUES ('3', 20, ST_GeomFromText('POINT(6720728 016569)', 3006))'''
        )
        db_utils.sql_alter_db(
            '''INSERT INTO stratigraphy (obsid, stratid, depthtop, depthbot, geology, geoshort, capacity, development) VALUES ('1', 1, 0, 1, 'sand', 'sand', '3', 'j')'''
        )
        db_utils.sql_alter_db(
            '''INSERT INTO stratigraphy (obsid, stratid, depthtop, depthbot, geology, geoshort, capacity, development) VALUES ('1', 2, 1, 4.5, 'morän', 'morän', '3', 'j')'''
        )

        self.create_and_select_vlayer()

        #print(str(self.vlayer.isValid()))
        #print(str(db_utils.sql_load_fr_db('select * from obs_points')))
        #print(str(db_utils.sql_load_fr_db('select * from stratigraphy')))
        dlg = Stratigraphy(self.iface, self.vlayer,
                           self.midvatten.ms.settingsdict)
        #print(str(mock_messagebar.mock_calls))
        #print(str(mock_skippopup.mock_calls))
        dlg.showSurvey()
        test = utils.anything_to_string_representation(dlg.data)
        test_survey = utils.anything_to_string_representation(
            repr(dlg.data['1']))
        test_strata = utils.anything_to_string_representation(
            utils.returnunicode(dlg.data['1'].strata, keep_containers=True))

        assert len(mock_skippopup.mock_calls) == 0
        print(str(mock_messagebar.mock_calls))
        assert len(mock_messagebar.mock_calls) == 0
        assert test == """{"1": SURVEY('1', 5.000000, '<QgsPointXY: POINT(633466 711659)>')}"""
        assert test_survey == '''"SURVEY('1', 5.000000, '<QgsPointXY: POINT(633466 711659)>')"'''
        print("test_strata: " + test_strata)
        assert test_strata == '''["strata(1, '3', 'sand', 'sand', 0.000000-1.000000)", "strata(2, '3', 'morän', 'moran', 1.000000-4.500000)"]'''
    def test_stratigraphy_missing_h_gs(self, mock_skippopup, mock_messagebar):
        """
        
        :param mock_skippopup:
        :param mock_messagebar:
        :return:
        """
        db_utils.sql_alter_db('''INSERT INTO obs_points (obsid, h_gs, geometry) VALUES ('1', 5, ST_GeomFromText('POINT(633466 711659)', 3006))''')
        db_utils.sql_alter_db('''INSERT INTO obs_points (obsid, h_gs, h_toc, geometry) VALUES ('2', NULL, 10, ST_GeomFromText('POINT(6720727 016568)', 3006))''')
        db_utils.sql_alter_db('''INSERT INTO obs_points (obsid, geometry) VALUES ('3', ST_GeomFromText('POINT(6720728 016569)', 3006))''')
        db_utils.sql_alter_db('''INSERT INTO stratigraphy (obsid, stratid, depthtop, depthbot, geology, geoshort, capacity, development) VALUES ('1', 1, 0, 1, 'sand', 'sand', '3', 'j')''')
        db_utils.sql_alter_db('''INSERT INTO stratigraphy (obsid, stratid, depthtop, depthbot, geology, geoshort, capacity, development) VALUES ('1', 2, 1, 4.5, 'morän', 'morän', '3', 'j')''')
        db_utils.sql_alter_db('''INSERT INTO stratigraphy (obsid, stratid, depthtop, depthbot, geology, geoshort, capacity, development) VALUES ('2', 1, 0, 1, 'sand', 'sand', '3', 'j')''')
        db_utils.sql_alter_db('''INSERT INTO stratigraphy (obsid, stratid, depthtop, depthbot, geology, geoshort, capacity, development) VALUES ('2', 2, 1, 4.5, 'morän', 'morän', '3', 'j')''')
        db_utils.sql_alter_db('''INSERT INTO stratigraphy (obsid, stratid, depthtop, depthbot, geology, geoshort, capacity, development) VALUES ('3', 1, 0, 2, 'sand', 'sand', '3', 'j')''')
        db_utils.sql_alter_db('''INSERT INTO stratigraphy (obsid, stratid, depthtop, depthbot, geology, geoshort, capacity, development) VALUES ('3', 2, 2, 6, 'morän', 'morän', '3', 'j')''')
        self.create_and_select_vlayer()

        dlg = Stratigraphy(self.iface, self.vlayer, self.ms.settingsdict)

        dlg.showSurvey()
        test = utils.anything_to_string_representation(dlg.data)
        test_survey = utils.anything_to_string_representation(repr(dlg.data['1']))
        test_strata = utils.anything_to_string_representation(utils.returnunicode(dlg.data['1'].strata, keep_containers=True))

        assert len(mock_skippopup.mock_calls) == 1
        print(str(mock_skippopup.mock_calls))
        print(str(mock_messagebar.mock_calls))
        assert mock_skippopup.mock_calls == [mock.call('Warning, h_gs is missing. See messagebar.')]
        assert mock_messagebar.mock_calls == [mock.call.warning(bar_msg="Obsid 2: using h_gs '' failed, using 'h_toc' instead.", duration=90, log_msg='False'),
                                              mock.call.warning(bar_msg="Obsid 3: using h_gs '' failed, using '-1' instead.", duration=90, log_msg='False')]
        print("test: " + test)
        assert test == """{"1": SURVEY('1', 5.000000, '<QgsPointXY: POINT(633466 711659)>'), "2": SURVEY('2', 10.000000, '<QgsPointXY: POINT(6720727 16568)>'), "3": SURVEY('3', -1.000000, '<QgsPointXY: POINT(6720728 16569)>')}"""
        print("test_survey " + test_survey)
        assert test_survey == '''"SURVEY('1', 5.000000, '<QgsPointXY: POINT(633466 711659)>')"'''
        print("Test strata " + test_strata)
        assert test_strata == '''["strata(1, '3', 'sand', 'sand', 0.000000-1.000000)", "strata(2, '3', 'morän', 'moran', 1.000000-4.500000)"]'''
예제 #4
0
    def test_stratigraphy_missing_h_gs(self, mock_skippopup, mock_messagebar):
        """
        
        :param mock_skippopup:
        :param mock_messagebar:
        :return:
        """
        db_utils.sql_alter_db(
            '''INSERT INTO obs_points (obsid, h_gs, geometry) VALUES ('1', 5, ST_GeomFromText('POINT(633466 711659)', 3006))'''
        )
        db_utils.sql_alter_db(
            '''INSERT INTO obs_points (obsid, h_gs, h_toc, geometry) VALUES ('2', NULL, 10, ST_GeomFromText('POINT(6720727 016568)', 3006))'''
        )
        db_utils.sql_alter_db(
            '''INSERT INTO obs_points (obsid, geometry) VALUES ('3', ST_GeomFromText('POINT(6720728 016569)', 3006))'''
        )
        db_utils.sql_alter_db(
            '''INSERT INTO stratigraphy (obsid, stratid, depthtop, depthbot, geology, geoshort, capacity, development) VALUES ('1', 1, 0, 1, 'sand', 'sand', '3', 'j')'''
        )
        db_utils.sql_alter_db(
            '''INSERT INTO stratigraphy (obsid, stratid, depthtop, depthbot, geology, geoshort, capacity, development) VALUES ('1', 2, 1, 4.5, 'morän', 'morän', '3', 'j')'''
        )
        db_utils.sql_alter_db(
            '''INSERT INTO stratigraphy (obsid, stratid, depthtop, depthbot, geology, geoshort, capacity, development) VALUES ('2', 1, 0, 1, 'sand', 'sand', '3', 'j')'''
        )
        db_utils.sql_alter_db(
            '''INSERT INTO stratigraphy (obsid, stratid, depthtop, depthbot, geology, geoshort, capacity, development) VALUES ('2', 2, 1, 4.5, 'morän', 'morän', '3', 'j')'''
        )
        db_utils.sql_alter_db(
            '''INSERT INTO stratigraphy (obsid, stratid, depthtop, depthbot, geology, geoshort, capacity, development) VALUES ('3', 1, 0, 2, 'sand', 'sand', '3', 'j')'''
        )
        db_utils.sql_alter_db(
            '''INSERT INTO stratigraphy (obsid, stratid, depthtop, depthbot, geology, geoshort, capacity, development) VALUES ('3', 2, 2, 6, 'morän', 'morän', '3', 'j')'''
        )
        self.create_and_select_vlayer()

        dlg = Stratigraphy(self.iface, self.vlayer, self.ms.settingsdict)

        dlg.showSurvey()
        test = utils.anything_to_string_representation(dlg.data)
        test_survey = utils.anything_to_string_representation(
            repr(dlg.data['1']))
        test_strata = utils.anything_to_string_representation(
            utils.returnunicode(dlg.data['1'].strata, keep_containers=True))

        assert len(mock_skippopup.mock_calls) == 1
        print(str(mock_skippopup.mock_calls))
        print(str(mock_messagebar.mock_calls))
        assert mock_skippopup.mock_calls == [
            mock.call('Warning, h_gs is missing. See messagebar.')
        ]
        assert mock_messagebar.mock_calls == [
            mock.call.warning(
                bar_msg="Obsid 2: using h_gs '' failed, using 'h_toc' instead.",
                duration=90,
                log_msg='False'),
            mock.call.warning(
                bar_msg="Obsid 3: using h_gs '' failed, using '-1' instead.",
                duration=90,
                log_msg='False')
        ]
        print("test: " + test)
        assert test == """{"1": SURVEY('1', 5.000000, '<QgsPointXY: POINT(633466 711659)>'), "2": SURVEY('2', 10.000000, '<QgsPointXY: POINT(6720727 16568)>'), "3": SURVEY('3', -1.000000, '<QgsPointXY: POINT(6720728 16569)>')}"""
        print("test_survey " + test_survey)
        assert test_survey == '''"SURVEY('1', 5.000000, '<QgsPointXY: POINT(633466 711659)>')"'''
        print("Test strata " + test_strata)
        assert test_strata == '''["strata(1, '3', 'sand', 'sand', 0.000000-1.000000)", "strata(2, '3', 'morän', 'moran', 1.000000-4.500000)"]'''