当前位置: 首页>>代码示例>>Python>>正文


Python Config.update方法代码示例

本文整理汇总了Python中simple_virtuoso_migrate.config.Config.update方法的典型用法代码示例。如果您正苦于以下问题:Python Config.update方法的具体用法?Python Config.update怎么用?Python Config.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在simple_virtuoso_migrate.config.Config的用法示例。


在下文中一共展示了Config.update方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_it_should_transform_keys_to_lower_case

# 需要导入模块: from simple_virtuoso_migrate.config import Config [as 别名]
# 或者: from simple_virtuoso_migrate.config.Config import update [as 别名]
 def test_it_should_transform_keys_to_lower_case(self):
     config = Config()
     config.put("sOmE_kEy", "original_value")
     self.assertEqual("original_value", config.get("SoMe_KeY"))
     config.update("sOMe_kEy", "new_value")
     self.assertEqual("new_value", config.get("some_KEY"))
     config.remove("SOME_KEY")
     self.assertRaises(Exception, config.get, "sOMe_KEY")
开发者ID:icaromedeiros,项目名称:simple-virtuoso-migrate,代码行数:10,代码来源:config_test.py

示例2: Config

# 需要导入模块: from simple_virtuoso_migrate.config import Config [as 别名]
# 或者: from simple_virtuoso_migrate.config.Config import update [as 别名]
 def test_it_should_update_value_to_a_existing_key_keeping_original_value_if_new_value_is_none_false_or_empty_string(self):
     config = Config()
     config.put("some_key", "original_value")
     config.update("some_key", None)
     self.assertEqual("original_value", config.get("some_key"))
     config.update("some_key", False)
     self.assertEqual("original_value", config.get("some_key"))
     config.update("some_key", "")
     self.assertEqual("original_value", config.get("some_key"))
开发者ID:icaromedeiros,项目名称:simple-virtuoso-migrate,代码行数:11,代码来源:config_test.py

示例3: VirtuosoTest

# 需要导入模块: from simple_virtuoso_migrate.config import Config [as 别名]
# 或者: from simple_virtuoso_migrate.config.Config import update [as 别名]

#.........这里部分代码省略.........
        self.assertEqual(lines_down[-1], expected_log_migration_down.replace('<log>', "\n".join(lines_up[0:-1]).replace('"','\\"').replace('\n', '\\n')))

        matchObj = re.search(r"SPARQL DELETE FROM <test> {(.*)} WHERE {(.*)};", query_down,  re.MULTILINE)
        sub_classes_01 = [c.strip(' \t\n\r') for c in re.split(r" ; | \?s\. \?s ", matchObj.group(1))]
        sub_classes_02 = [c.strip(' \t\n\r') for c in re.split(r" ; | \?s\. \?s ", matchObj.group(2))]
        [self.assertTrue((c in sub_classes_01) and (c in sub_classes_02)) for c in [
            '<http://example.com/role> <http://www.w3.org/2000/01/rdf-schema#subClassOf>',
            '<http://www.w3.org/2002/07/owl#minQualifiedCardinality> "1"^^<http://www.w3.org/2001/XMLSchema#integer>',
            '<http://www.w3.org/2002/07/owl#maxQualifiedCardinality> "1"^^<http://www.w3.org/2001/XMLSchema#integer>',
            '<http://www.w3.org/2002/07/owl#onClass> <http://example.com/RoleOnSoapOpera>',
            '<http://www.w3.org/2002/07/owl#onProperty> <http://example.com/play_a_role>',
            '<http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Restriction>'
            ]]


    def test_it_should_get_sparql_statments_when_backward_migration(self):

        query_up, query_down = Virtuoso(self.config).get_sparql(current_ontology=self.structure_02_ttl_content, destination_ontology=self.structure_01_ttl_content, origen='file', destination_version='01')


        expected_lines_up = ["SPARQL DELETE FROM <test> {<http://example.com/role> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Class> . };",
                             "SPARQL DELETE FROM <test> {<http://example.com/RoleOnSoapOpera> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Class> . };",
                            ]

        expected_log_migration_up = """SPARQL INSERT INTO <http://example.com/> { [] owl:versionInfo "01"; <http://example.com/endpoint> "endpoint"; <http://example.com/usuario> "user"; <http://example.com/ambiente> "localhost"; <http://example.com/produto> "test"; <http://example.com/commited> "%s"^^xsd:dateTime; <http://example.com/origen> "file"; <http://example.com/changes> "\\n<log>".};""" % datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")

        expected_lines_down = ["SPARQL INSERT INTO <test> {<http://example.com/RoleOnSoapOpera> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Class> . };",
                             "SPARQL INSERT INTO <test> {<http://example.com/role> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Class> . };",
                            ]

        expected_log_migration_down = """SPARQL DELETE FROM <http://example.com/> {?s ?p ?o} WHERE {?s owl:versionInfo "01"; <http://example.com/endpoint> "endpoint"; <http://example.com/usuario> "user"; <http://example.com/ambiente> "localhost"; <http://example.com/produto> "test"; <http://example.com/commited> "%s"^^xsd:dateTime; <http://example.com/origen> "file"; <http://example.com/changes> "\\n<log>"; ?p ?o.};""" % datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")

        """SPARQL INSERT INTO <http://example.com/> { [] owl:versionInfo "01"; <http://example.com/endpoint> "endpoint"; <http://example.com/usuario> "user"; <http://example.com/ambiente> "localhost"; <http://example.com/produto> "test"; <http://example.com/commited> "%s"^^xsd:dateTime; <http://example.com/origen> "file"; <http://example.com/changes> "\\n<log>".};""" % datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")

        lines_up = query_up.strip(' \t\n\r').splitlines()
        self.assertEqual(4, len(lines_up))
        [self.assertTrue(l in lines_up) for l in expected_lines_up]
        self.assertEqual(lines_up[-1], expected_log_migration_up.replace('<log>', "\n".join(lines_up[0:-1]).replace('"','\\"').replace('\n', '\\n')))

        matchObj = re.search(r"SPARQL DELETE FROM <test> {(.*)} WHERE {(.*)};", query_up,  re.MULTILINE)
        sub_classes_01 = [c.strip(' \t\n\r') for c in re.split(r" ; | \?s\. \?s ", matchObj.group(1))]
        sub_classes_02 = [c.strip(' \t\n\r') for c in re.split(r" ; | \?s\. \?s ", matchObj.group(2))]
        [self.assertTrue((c in sub_classes_01) and (c in sub_classes_02)) for c in [
            '<http://example.com/role> <http://www.w3.org/2000/01/rdf-schema#subClassOf>',
            '<http://www.w3.org/2002/07/owl#minQualifiedCardinality> "1"^^<http://www.w3.org/2001/XMLSchema#integer>',
            '<http://www.w3.org/2002/07/owl#maxQualifiedCardinality> "1"^^<http://www.w3.org/2001/XMLSchema#integer>',
            '<http://www.w3.org/2002/07/owl#onClass> <http://example.com/RoleOnSoapOpera>',
            '<http://www.w3.org/2002/07/owl#onProperty> <http://example.com/play_a_role>',
            '<http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Restriction>'
            ]]


        lines_down = query_down.strip(' \t\n\r').splitlines()
        self.assertEqual(4, len(lines_down))
        [self.assertTrue(l in lines_down) for l in expected_lines_down]
        self.assertEqual(lines_down[-1], expected_log_migration_down.replace('<log>', "\n".join(lines_up[0:-1]).replace('"','\\"').replace('\n', '\\n')))

        matchObj = re.search(r"SPARQL INSERT INTO <test> { <http://example.com/role> <http://www.w3.org/2000/01/rdf-schema#subClassOf> \[(.*)\] };", query_down,  re.MULTILINE)
        sub_classes = [c.strip(' \t\n\r') for c in re.split(r" ; | \?s\. \?s ", matchObj.group(1))]
        [self.assertTrue(c in sub_classes) for c in [
            '<http://www.w3.org/2002/07/owl#minQualifiedCardinality> "1"^^<http://www.w3.org/2001/XMLSchema#integer>',
            '<http://www.w3.org/2002/07/owl#maxQualifiedCardinality> "1"^^<http://www.w3.org/2001/XMLSchema#integer>',
            '<http://www.w3.org/2002/07/owl#onClass> <http://example.com/RoleOnSoapOpera>',
            '<http://www.w3.org/2002/07/owl#onProperty> <http://example.com/play_a_role>',
            '<http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Restriction>'
            ]]

#    @patch('simple_virtuoso_migrate.virtuoso.Virtuoso.get_sparql')
#    def test_it_should_get_statments_to_execute_when_comparing_the_given_file_with_the_current_version(self, get_sparql_mock):
#        Virtuoso(self.config).get_statements("data.ttl", current_version='01', origen='file')
#        get_sparql_mock.assert_called_with(None, self.data_ttl_content, '01', None, 'file', 'data.ttl')

#    def test_it_should_raise_exception_when_getting_statments_of_an_unexistent_ttl_file(self):
#        self.assertRaisesWithMessage(Exception, 'migration file does not exist (current_file.ttl)', Virtuoso(self.config).get_statements, "current_file.ttl", current_version='01', origen='file')

    def test_it_should_raise_exception_if_specified_ontology_does_not_exists_on_migrations_dir(self):
        self.config.update('database_ontology', 'ontology.ttl')
        self.config.update('database_migrations_dir', '.')
        self.assertRaisesWithMessage(Exception, 'migration file does not exist (./ontology.ttl)', Virtuoso(self.config).get_ontology_by_version, '01')

    @patch('simple_virtuoso_migrate.virtuoso.Git')
    def test_it_should_return_git_content(self, git_mock):
        execute_mock = Mock(**{'return_value':'content'})
        git_mock.return_value = Mock(**{'execute':execute_mock})

        content = Virtuoso(self.config).get_ontology_by_version('version')
        self.assertEqual('content', content)
        git_mock.assert_called_with('.')
        execute_mock.assert_called_with(['git', 'show', 'version:test.ttl'])

    def test_it_should_print_error_message_with_correct_encoding(self):
        graph = """
        :is_part_of rdf:type owl:ObjectProperty ;
                     rdfs:label "É parte de outro objeto" ;
                     rdfs:domain absent:Prefix ;
                     rdfs:range absent:Prefix .
        """

        expected_message = 'Error parsing graph at line 2 of <>:\nBad syntax (Prefix ":" not bound) at ^ in:\n"\n        ^:is_part_of rdf:type owl:ObjectProperty ;\n                  ..."'
        self.assertRaisesWithMessage(Exception, expected_message, Virtuoso(self.config).get_sparql, current_ontology=None, destination_ontology=graph)
开发者ID:globocom,项目名称:simple-virtuoso-migrate,代码行数:104,代码来源:virtuoso_test.py

示例4: test_it_should_update_value_to_a_existing_key

# 需要导入模块: from simple_virtuoso_migrate.config import Config [as 别名]
# 或者: from simple_virtuoso_migrate.config.Config import update [as 别名]
 def test_it_should_update_value_to_a_existing_key(self):
     config = Config()
     config.put("some_key", "original_value")
     config.update("some_key", "some_value")
     self.assertEqual("some_value", config.get("some_key"))
开发者ID:icaromedeiros,项目名称:simple-virtuoso-migrate,代码行数:7,代码来源:config_test.py

示例5: VirtuosoTest

# 需要导入模块: from simple_virtuoso_migrate.config import Config [as 别名]
# 或者: from simple_virtuoso_migrate.config.Config import update [as 别名]

#.........这里部分代码省略.........

        expected_lines_up = [
            "SPARQL DELETE FROM <test> {<http://example.com/role> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Class> . };",
            "SPARQL DELETE FROM <test> {<http://example.com/RoleOnSoapOpera> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Class> . };",
        ]

        expected_log_migration_up = """SPARQL INSERT INTO <http://migration.example.com/> {[] owl:versionInfo "01"; <http://migration.example.com/endpoint> "endpoint"; <http://migration.example.com/usuario> "user"; <http://migration.example.com/ambiente> "localhost"; <http://migration.example.com/produto> "test"; <http://migration.example.com/commited> "%s"^^xsd:dateTime; <http://migration.example.com/origen> "file"; <http://migration.example.com/changes> "\\n<log>".};""" % datetime.datetime.now().strftime(
            "%Y-%m-%d %H:%M:%S"
        )

        expected_lines_down = [
            "SPARQL INSERT INTO <test> {<http://example.com/RoleOnSoapOpera> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Class> . };",
            "SPARQL INSERT INTO <test> {<http://example.com/role> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Class> . };",
        ]

        expected_log_migration_down = """SPARQL DELETE FROM <http://migration.example.com/> {?s ?p ?o} WHERE {?s owl:versionInfo "01"; <http://migration.example.com/endpoint> "endpoint"; <http://migration.example.com/usuario> "user"; <http://migration.example.com/ambiente> "localhost"; <http://migration.example.com/produto> "test"; <http://migration.example.com/commited> "%s"^^xsd:dateTime; <http://migration.example.com/origen> "file"; <http://migration.example.com/changes> "\\n<log>"; ?p ?o.};""" % datetime.datetime.now().strftime(
            "%Y-%m-%d %H:%M:%S"
        )

        """SPARQL INSERT INTO <http://migration.example.com/> {[] owl:versionInfo "01"; <http://migration.example.com/endpoint> "endpoint"; <http://migration.example.com/usuario> "user"; <http://migration.example.com/ambiente> "localhost"; <http://migration.example.com/produto> "test"; <http://migration.example.com/commited> "%s"^^xsd:dateTime; <http://migration.example.com/origen> "file"; <http://migration.example.com/changes> "\\n<log>".};""" % datetime.datetime.now().strftime(
            "%Y-%m-%d %H:%M:%S"
        )

        lines_up = query_up.strip(" \t\n\r").splitlines()
        self.assertEqual(4, len(lines_up))
        [self.assertTrue(l in lines_up) for l in expected_lines_up]
        # self.assertEqual(lines_up[-1], expected_log_migration_up.replace('<log>', "\n".join(lines_up[0:-1]).replace('"','\\"').replace('\n', '\\n')))

        #        matchObj = re.search(r"SPARQL DELETE FROM <test> {(.*)} WHERE {(.*)};", query_up,  re.MULTILINE)
        #        sub_classes_01 = [c.strip(' \t\n\r') for c in re.split(r" ; | \?s\. \?s ", matchObj.group(1))]
        #        sub_classes_02 = [c.strip(' \t\n\r') for c in re.split(r" ; | \?s\. \?s ", matchObj.group(2))]
        #        [self.assertTrue((c in sub_classes_01) and (c in sub_classes_02)) for c in [
        #            '<http://example.com/role> <http://www.w3.org/2000/01/rdf-schema#subClassOf>',
        #            '<http://www.w3.org/2002/07/owl#minQualifiedCardinality> "1"^^<http://www.w3.org/2001/XMLSchema#nonNegativeInteger>',
        #            '<http://www.w3.org/2002/07/owl#maxQualifiedCardinality> "1"^^<http://www.w3.org/2001/XMLSchema#nonNegativeInteger>',
        #            '<http://www.w3.org/2002/07/owl#onClass> <http://example.com/RoleOnSoapOpera>',
        #            '<http://www.w3.org/2002/07/owl#onProperty> <http://example.com/play_a_role>',
        #            '<http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Restriction>'
        #            ]]

        lines_down = query_down.strip(" \t\n\r").splitlines()
        self.assertEqual(4, len(lines_down))
        [self.assertTrue(l in lines_down) for l in expected_lines_down]

    #        self.assertEqual(lines_down[-1], expected_log_migration_down.replace('<log>', "\n".join(lines_up[0:-1]).replace('"','\\"').replace('\n', '\\n')))

    #        matchObj = re.search(r"SPARQL INSERT INTO <test> { <http://example.com/role> <http://www.w3.org/2000/01/rdf-schema#subClassOf> \[(.*)\] };", query_down,  re.MULTILINE)
    #        sub_classes = [c.strip(' \t\n\r') for c in re.split(r" ; | \?s\. \?s ", matchObj.group(1))]
    #        [self.assertTrue(c in sub_classes) for c in [
    #            '<http://www.w3.org/2002/07/owl#minQualifiedCardinality> "1"^^<http://www.w3.org/2001/XMLSchema#nonNegativeInteger>',
    #            '<http://www.w3.org/2002/07/owl#maxQualifiedCardinality> "1"^^<http://www.w3.org/2001/XMLSchema#nonNegativeInteger>',
    #            '<http://www.w3.org/2002/07/owl#onClass> <http://example.com/RoleOnSoapOpera>',
    #            '<http://www.w3.org/2002/07/owl#onProperty> <http://example.com/play_a_role>',
    #            '<http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Restriction>'
    #            ]]

    #    @patch('simple_virtuoso_migrate.virtuoso.Virtuoso.get_sparql')
    #    def test_it_should_get_statments_to_execute_when_comparing_the_given_file_with_the_current_version(self, get_sparql_mock):
    #        Virtuoso(self.config).get_statements("data.ttl", current_version='01', origen='file')
    #        get_sparql_mock.assert_called_with(None, self.data_ttl_content, '01', None, 'file', 'data.ttl')

    #    def test_it_should_raise_exception_when_getting_statments_of_an_unexistent_ttl_file(self):
    #        self.assertRaisesWithMessage(Exception, 'migration file does not exist (current_file.ttl)', Virtuoso(self.config).get_statements, "current_file.ttl", current_version='01', origen='file')

    def test_it_should_raise_exception_if_specified_ontology_does_not_exists_on_migrations_dir(self):
        self.config.update("database_ontology", "ontology.ttl")
        self.config.update("database_migrations_dir", ".")
        self.assertRaisesWithMessage(
            Exception,
            "migration file does not exist (./ontology.ttl)",
            Virtuoso(self.config).get_ontology_by_version,
            "01",
        )

    @patch("simple_virtuoso_migrate.virtuoso.Git")
    def test_it_should_return_git_content(self, git_mock):
        execute_mock = Mock(**{"return_value": "content"})
        git_mock.return_value = Mock(**{"execute": execute_mock})

        content = Virtuoso(self.config).get_ontology_by_version("version")
        self.assertEqual("content", content)
        git_mock.assert_called_with(".")
        execute_mock.assert_called_with(["git", "show", "version:test.ttl"])

    def test_it_should_print_error_message_with_correct_encoding(self):
        graph = """
        :is_part_of rdf:type owl:ObjectProperty ;
                     rdfs:label "É parte de outro objeto" ;
                     rdfs:domain absent:Prefix ;
                     rdfs:range absent:Prefix .
        """

        expected_message = 'Error parsing graph at line 2 of <>:\nBad syntax (Prefix ":" not bound) at ^ in:\n"\n        ^:is_part_of rdf:type owl:ObjectProperty ;\n                  ..."'
        self.assertRaisesWithMessage(
            Exception,
            expected_message,
            Virtuoso(self.config).get_sparql,
            current_ontology=None,
            destination_ontology=graph,
        )
开发者ID:viniciuschagas,项目名称:simple-virtuoso-migrate,代码行数:104,代码来源:virtuoso_test.py


注:本文中的simple_virtuoso_migrate.config.Config.update方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。