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


Python Cleaners.capitalize方法代码示例

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


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

示例1: test_post_mistyped_uof_data

# 需要导入模块: from comport.data.cleaners import Cleaners [as 别名]
# 或者: from comport.data.cleaners.Cleaners import capitalize [as 别名]
    def test_post_mistyped_uof_data(self, testapp):
        ''' New UOF data from the extractor is processed as expected.
        '''
        # Set up the extractor
        department = Department.create(name="Good Police Department", short_name="GPD", load_defaults=False)
        extractor, envs = Extractor.from_department_and_password(department=department, password="password")

        # Set the correct authorization
        testapp.authorization = ('Basic', (extractor.username, 'password'))

        # Get a generated list of UOF descriptions from the JSON test client
        test_client = JSONTestClient()
        uof_count = 1
        uof_data = test_client.get_prebaked_uof(last=uof_count)

        # The app expects number values to be transmitted as strings. Let's change them to integers.
        uof_data[0]['residentAge'] = 28
        uof_data[0]['officerAge'] = 46
        uof_data[0]['officerYearsOfService'] = 17

        # post the json to the UOF URL
        response = testapp.post_json("/data/UOF", params={'month': 0, 'year': 0, 'data': uof_data})

        # assert that we got the expected reponse
        assert response.status_code == 200
        assert response.json_body['updated'] == 0
        assert response.json_body['added'] == uof_count

        # check the uof incident in the database against the data that was sent
        cleaner = Cleaners()
        sent_uof = uof_data[0]
        check_uof = UseOfForceIncident.query.filter_by(opaque_id=sent_uof['opaqueId']).first()
        assert check_uof.occured_date.strftime('%Y-%m-%d %-H:%-M:%S') == sent_uof['occuredDate']
        assert check_uof.division == cleaner.capitalize(sent_uof['division'])
        assert check_uof.precinct == cleaner.capitalize(sent_uof['precinct'])
        assert check_uof.shift == cleaner.capitalize(sent_uof['shift'])
        assert check_uof.beat == cleaner.capitalize(sent_uof['beat'])
        assert check_uof.disposition == sent_uof['disposition']
        assert check_uof.officer_force_type == cleaner.officer_force_type(sent_uof['officerForceType'])
        assert check_uof.use_of_force_reason == sent_uof['useOfForceReason']
        assert check_uof.service_type == sent_uof['serviceType']
        assert check_uof.arrest_made == sent_uof['arrestMade']
        assert check_uof.arrest_charges == sent_uof['arrestCharges']
        assert check_uof.resident_weapon_used == sent_uof['residentWeaponUsed']
        assert check_uof.resident_injured == sent_uof['residentInjured']
        assert check_uof.resident_hospitalized == sent_uof['residentHospitalized']
        assert check_uof.officer_injured == sent_uof['officerInjured']
        assert check_uof.officer_hospitalized == sent_uof['officerHospitalized']
        assert check_uof.resident_race == cleaner.race(sent_uof['residentRace'])
        assert check_uof.resident_sex == cleaner.sex(sent_uof['residentSex'])
        assert check_uof.resident_age == cleaner.number_to_string(sent_uof['residentAge'])
        assert check_uof.resident_condition == sent_uof['residentCondition']
        assert check_uof.officer_identifier == sent_uof['officerIdentifier']
        assert check_uof.officer_race == cleaner.race(sent_uof['officerRace'])
        assert check_uof.officer_sex == cleaner.sex(sent_uof['officerSex'])
        assert check_uof.officer_age == cleaner.number_to_string(sent_uof['officerAge'])
        assert check_uof.officer_years_of_service == cleaner.number_to_string(sent_uof['officerYearsOfService'])
        assert check_uof.officer_condition == sent_uof['officerCondition']
开发者ID:carolynjoneslee,项目名称:comport,代码行数:60,代码来源:test_extractor_api.py

示例2: test_captilization_handles_non_strings

# 需要导入模块: from comport.data.cleaners import Cleaners [as 别名]
# 或者: from comport.data.cleaners.Cleaners import capitalize [as 别名]
 def test_captilization_handles_non_strings(self):
     """ Non-strings passed to capitalize aren't altered.
     """
     cleaner = Cleaners()
     send_int = 23
     send_float = 32.01
     send_list = ["I", "thought", "I", "would", "sail"]
     result_int = cleaner.capitalize(send_int)
     result_float = cleaner.capitalize(send_float)
     result_list = cleaner.capitalize(send_list)
     assert send_int == result_int
     assert send_float == result_float
     assert send_list == result_list
开发者ID:codeforamerica,项目名称:comport,代码行数:15,代码来源:test_cleaners.py

示例3: test_post_mistyped_ois_data

# 需要导入模块: from comport.data.cleaners import Cleaners [as 别名]
# 或者: from comport.data.cleaners.Cleaners import capitalize [as 别名]
    def test_post_mistyped_ois_data(self, testapp):
        ''' New OIS data from the extractor is processed as expected.
        '''
        # Set up the extractor
        department = Department.create(name="Good Police Department", short_name="GPD", load_defaults=False)
        extractor, envs = Extractor.from_department_and_password(department=department, password="password")

        # Set the correct authorization
        testapp.authorization = ('Basic', (extractor.username, 'password'))

        # Get a generated list of OIS descriptions from the JSON test client
        test_client = JSONTestClient()
        ois_count = 1
        ois_data = test_client.get_prebaked_ois(last=ois_count)

        # The app expects number values to be transmitted as strings. Let's change them to integers.
        ois_data[0]['residentAge'] = 28
        ois_data[0]['officerAge'] = 46
        # And it expects this number value to be transmitted as a number, so let's make it a string.
        ois_data[0]['officerYearsOfService'] = "17"

        # post the json to the OIS URL
        response = testapp.post_json("/data/OIS", params={'month': 0, 'year': 0, 'data': ois_data})

        # assert that we got the expected reponse
        assert response.status_code == 200
        assert response.json_body['updated'] == 0
        assert response.json_body['added'] == ois_count

        # check the ois incident in the database against the data that was sent
        cleaner = Cleaners()
        sent_ois = ois_data[0]
        check_ois = OfficerInvolvedShooting.query.filter_by(opaque_id=sent_ois['opaqueId']).first()
        assert check_ois.occured_date.strftime('%Y-%m-%d %-H:%-M:%S') == sent_ois['occuredDate']
        assert check_ois.division == cleaner.capitalize(sent_ois['division'])
        assert check_ois.precinct == cleaner.capitalize(sent_ois['precinct'])
        assert check_ois.shift == cleaner.capitalize(sent_ois['shift'])
        assert check_ois.beat == cleaner.capitalize(sent_ois['beat'])
        assert check_ois.disposition == sent_ois['disposition']
        assert check_ois.resident_race == cleaner.race(sent_ois['residentRace'])
        assert check_ois.resident_sex == cleaner.sex(sent_ois['residentSex'])
        assert check_ois.resident_age == cleaner.number_to_string(sent_ois['residentAge'])
        assert check_ois.resident_weapon_used == cleaner.resident_weapon_used(sent_ois['residentWeaponUsed'])
        assert check_ois.resident_condition == sent_ois['residentCondition']
        assert check_ois.officer_identifier == sent_ois['officerIdentifier']
        assert check_ois.officer_weapon_used == sent_ois['officerForceType']
        assert check_ois.officer_race == cleaner.race(sent_ois['officerRace'])
        assert check_ois.officer_sex == cleaner.sex(sent_ois['officerSex'])
        assert check_ois.officer_age == cleaner.number_to_string(sent_ois['officerAge'])
        assert check_ois.officer_years_of_service == cleaner.string_to_integer(sent_ois['officerYearsOfService'])
        assert check_ois.officer_condition == sent_ois['officerCondition']
开发者ID:carolynjoneslee,项目名称:comport,代码行数:53,代码来源:test_extractor_api.py

示例4: upgrade

# 需要导入模块: from comport.data.cleaners import Cleaners [as 别名]
# 或者: from comport.data.cleaners.Cleaners import capitalize [as 别名]
def upgrade():
    complaints = CitizenComplaintIMPD.query.all()
    cleaner = Cleaners()
    for complaint in complaints:
        new_allegation = cleaner.capitalize(complaint.allegation)
        if complaint.allegation != new_allegation:
            complaint.update(allegation=new_allegation)
开发者ID:codeforamerica,项目名称:comport,代码行数:9,代码来源:43c4c512514_.py

示例5: test_capitalization

# 需要导入模块: from comport.data.cleaners import Cleaners [as 别名]
# 或者: from comport.data.cleaners.Cleaners import capitalize [as 别名]
 def test_capitalization(self):
     ''' A phrase is title-cased with expected exceptions.
     '''
     in_sentence = "I thought I would sail about a little and see the watery part of the world"
     titlecased_sentence = titlecase(in_sentence)
     send = " ".join(i.lower() + " " + j.lower() for i, j in zip(in_sentence.split(" "), CAPITALIZE_LIST))
     check = " ".join(i + " " + j for i, j in zip(titlecased_sentence.split(" "), CAPITALIZE_LIST))
     result = Cleaners.capitalize(send)
     assert check == result
开发者ID:mehmadi,项目名称:comport,代码行数:11,代码来源:test_cleaners.py

示例6: test_update_ois_data

# 需要导入模块: from comport.data.cleaners import Cleaners [as 别名]
# 或者: from comport.data.cleaners.Cleaners import capitalize [as 别名]
    def test_update_ois_data(self, testapp):
        ''' Updated OIS data from the extractor is processed as expected.
        '''
        # Set up the extractor
        department = Department.create(name="Good Police Department", short_name="GPD", load_defaults=False)
        extractor, envs = Extractor.from_department_and_password(department=department, password="password")

        # Set the correct authorization
        testapp.authorization = ('Basic', (extractor.username, 'password'))

        # Get a generated list of OIS descriptions from the JSON test client
        test_client = JSONTestClient()
        ois_data = test_client.get_prebaked_ois(last=1)
        # post the json to the OIS URL
        response = testapp.post_json("/data/OIS", params={'month': 0, 'year': 0, 'data': ois_data})

        # assert that we got the expected reponse
        assert response.status_code == 200
        assert response.json_body['updated'] == 0
        assert response.json_body['added'] == 1

        # Get the second pre-baked ois incident
        updated_ois_data = test_client.get_prebaked_ois(first=1, last=2)
        # Swap in the opaque ID from the first ois incident
        updated_ois_data[0]["opaqueId"] = ois_data[0]["opaqueId"]
        # The ois incident won't be a match unless this field is the same
        updated_ois_data[0]["officerIdentifier"] = ois_data[0]["officerIdentifier"]
        # post the json to the ois URL
        response = testapp.post_json("/data/OIS", params={'month': 0, 'year': 0, 'data': updated_ois_data})

        # assert that we got the expected reponse
        assert response.status_code == 200
        assert response.json_body['updated'] == 1
        assert response.json_body['added'] == 0

        # There's only one complaint in the database.
        all_ois = OfficerInvolvedShooting.query.all()
        assert len(all_ois) == 1

        # check the ois incident in the database against the updated data that was sent
        cleaner = Cleaners()
        sent_ois = updated_ois_data[0]
        check_ois = OfficerInvolvedShooting.query.filter_by(opaque_id=sent_ois['opaqueId']).first()
        assert check_ois.occured_date.strftime('%Y-%m-%d %-H:%-M:%S') == sent_ois['occuredDate']
        assert check_ois.division == cleaner.capitalize(sent_ois['division'])
        assert check_ois.precinct == cleaner.capitalize(sent_ois['precinct'])
        assert check_ois.shift == cleaner.capitalize(sent_ois['shift'])
        assert check_ois.beat == cleaner.capitalize(sent_ois['beat'])
        assert check_ois.disposition == sent_ois['disposition']
        assert check_ois.resident_race == cleaner.race(sent_ois['residentRace'])
        assert check_ois.resident_sex == cleaner.sex(sent_ois['residentSex'])
        assert check_ois.resident_age == cleaner.number_to_string(sent_ois['residentAge'])
        assert check_ois.resident_weapon_used == cleaner.resident_weapon_used(sent_ois['residentWeaponUsed'])
        assert check_ois.resident_condition == sent_ois['residentCondition']
        assert check_ois.officer_identifier == sent_ois['officerIdentifier']
        assert check_ois.officer_weapon_used == sent_ois['officerForceType']
        assert check_ois.officer_race == cleaner.race(sent_ois['officerRace'])
        assert check_ois.officer_sex == cleaner.sex(sent_ois['officerSex'])
        assert check_ois.officer_age == cleaner.number_to_string(sent_ois['officerAge'])
        assert check_ois.officer_years_of_service == cleaner.string_to_integer(sent_ois['officerYearsOfService'])
        assert check_ois.officer_condition == sent_ois['officerCondition']
开发者ID:carolynjoneslee,项目名称:comport,代码行数:63,代码来源:test_extractor_api.py

示例7: test_update_uof_data

# 需要导入模块: from comport.data.cleaners import Cleaners [as 别名]
# 或者: from comport.data.cleaners.Cleaners import capitalize [as 别名]
    def test_update_uof_data(self, testapp):
        ''' Updated UOF data from the extractor is processed as expected.
        '''
        # Set up the extractor
        department = Department.create(name="IM Police Department", short_name="IMPD", load_defaults=False)
        extractor, envs = Extractor.from_department_and_password(department=department, password="password")

        # Set the correct authorization
        testapp.authorization = ('Basic', (extractor.username, 'password'))

        # Get a generated list of UOF descriptions from the JSON test client
        test_client = JSONTestClient()
        uof_data = test_client.get_prebaked_uof(last=1)
        # post the json to the UOF URL
        response = testapp.post_json("/data/UOF", params={'month': 0, 'year': 0, 'data': uof_data})

        # assert that we got the expected reponse
        assert response.status_code == 200
        assert response.json_body['updated'] == 0
        assert response.json_body['added'] == 1

        # Get the second pre-baked uof incident
        updated_uof_data = test_client.get_prebaked_uof(first=1, last=2)
        # Swap in the opaque ID from the first uof incident
        updated_uof_data[0]["opaqueId"] = uof_data[0]["opaqueId"]
        # The uof incident won't be a match unless these fields are the same
        updated_uof_data[0]["officerIdentifier"] = uof_data[0]["officerIdentifier"]
        updated_uof_data[0]["officerForceType"] = uof_data[0]["officerForceType"]
        # post the json to the uof URL
        response = testapp.post_json("/data/UOF", params={'month': 0, 'year': 0, 'data': updated_uof_data})

        # assert that we got the expected reponse
        assert response.status_code == 200
        assert response.json_body['updated'] == 1
        assert response.json_body['added'] == 0

        # There's only one complaint in the database.
        all_uof = UseOfForceIncidentIMPD.query.all()
        assert len(all_uof) == 1

        # check the uof incident in the database against the updated data that was sent
        cleaner = Cleaners()
        sent_uof = updated_uof_data[0]
        check_uof = UseOfForceIncidentIMPD.query.filter_by(opaque_id=sent_uof['opaqueId']).first()
        assert check_uof.occured_date.strftime('%Y-%m-%d %-H:%-M:%S') == sent_uof['occuredDate']
        assert check_uof.division == cleaner.capitalize(sent_uof['division'])
        assert check_uof.precinct == cleaner.capitalize(sent_uof['precinct'])
        assert check_uof.shift == cleaner.capitalize(sent_uof['shift'])
        assert check_uof.beat == cleaner.capitalize(sent_uof['beat'])
        assert check_uof.disposition == sent_uof['disposition']
        assert check_uof.officer_force_type == cleaner.officer_force_type(sent_uof['officerForceType'])
        assert check_uof.use_of_force_reason == sent_uof['useOfForceReason']
        assert check_uof.service_type == sent_uof['serviceType']
        assert check_uof.arrest_made == sent_uof['arrestMade']
        assert check_uof.arrest_charges == sent_uof['arrestCharges']
        assert check_uof.resident_weapon_used == sent_uof['residentWeaponUsed']
        assert check_uof.resident_injured == sent_uof['residentInjured']
        assert check_uof.resident_hospitalized == sent_uof['residentHospitalized']
        assert check_uof.officer_injured == sent_uof['officerInjured']
        assert check_uof.officer_hospitalized == sent_uof['officerHospitalized']
        assert check_uof.resident_race == cleaner.race(sent_uof['residentRace'])
        assert check_uof.resident_sex == cleaner.sex(sent_uof['residentSex'])
        assert check_uof.resident_age == cleaner.number_to_string(sent_uof['residentAge'])
        assert check_uof.resident_condition == sent_uof['residentCondition']
        assert check_uof.officer_identifier == sent_uof['officerIdentifier']
        assert check_uof.officer_race == cleaner.race(sent_uof['officerRace'])
        assert check_uof.officer_sex == cleaner.sex(sent_uof['officerSex'])
        assert check_uof.officer_age == cleaner.number_to_string(sent_uof['officerAge'])
        assert check_uof.officer_years_of_service == cleaner.number_to_string(sent_uof['officerYearsOfService'])
        assert check_uof.officer_condition == sent_uof['officerCondition']
开发者ID:codeforamerica,项目名称:comport,代码行数:72,代码来源:test_extractor_api.py


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