Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(210)

Side by Side Diff: components/test/data/autofill/merge/tools/autofill_merge_common.py

Issue 1932193003: [Autofill] Modernize some AutofillMergeTest (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: mac import Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/test/data/autofill/merge/output/validation.out ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2013 The Chromium Authors. All rights reserved. 1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 5
6 class UnknownColumnNameException(Exception): 6 class UnknownColumnNameException(Exception):
7 """Exception type raised when encountering an unknown column name.""" 7 """Exception type raised when encountering an unknown column name."""
8 def __init__(self, column_name): 8 def __init__(self, column_name):
9 self.column_name = column_name 9 self.column_name = column_name
10 def __str__(self): 10 def __str__(self):
11 return repr(self.column_name) 11 return repr(self.column_name)
12 12
13 13
14 def SerializeProfiles(profiles): 14 def SerializeProfiles(profiles):
15 """Returns a serialized string for the given |profiles|. 15 """Returns a serialized string for the given |profiles|.
16 16
17 |profiles| should be a list of (field_type, value) string pairs. 17 |profiles| should be a list of (field_type, value) string pairs.
18 18
19 """ 19 """
20 20
21 lines = [] 21 lines = []
22 for profile in profiles: 22 for profile in profiles:
23 # Include a fixed string to separate profiles. 23 # Include a fixed string to separate profiles.
24 lines.append("---") 24 lines.append("---")
25 for (field_type, value) in profile: 25 for (field_type, value) in profile:
26 if field_type == "ignored": 26 if field_type == "ignored":
27 continue; 27 continue;
28 28
29 value = value.replace('\n', '\\n')
29 lines.append("%s: %s" % (field_type, value)) 30 lines.append("%s: %s" % (field_type, value))
30 31
31 return '\n'.join(lines) 32 return '\n'.join(lines)
32 33
33 34
34 def ColumnNameToFieldType(column_name): 35 def ColumnNameToFieldType(column_name):
35 """Converts the given |column_name| to the corresponding AutofillField type. 36 """Converts the given |column_name| to the corresponding AutofillField type.
36 37
37 |column_name| should be a string drawn from the column names of the 38 |column_name| should be a string drawn from the column names of the
38 autofill_profiles table in the Chromium "Web Data" database. 39 autofill_profiles table in the Chromium "Web Data" database.
39 40
40 """ 41 """
41 42
42 column_name = column_name.lower() 43 column_name = column_name.lower()
43 field_type = "unknown" 44 field_type = "unknown"
44 if column_name in ["guid", "label", "country", "date_modified", "origin", 45 if column_name in ["guid", "label", "country", "date_modified", "origin",
45 "language_code", "use_count", "use_date"]: 46 "language_code", "use_count", "use_date", "sorting_code",
47 "dependent_locality"]:
46 field_type = "ignored" 48 field_type = "ignored"
47 elif column_name == "first_name": 49 elif column_name == "first_name":
48 field_type = "NAME_FIRST" 50 field_type = "NAME_FIRST"
49 elif column_name == "middle_name": 51 elif column_name == "middle_name":
50 field_type = "NAME_MIDDLE" 52 field_type = "NAME_MIDDLE"
51 elif column_name == "last_name": 53 elif column_name == "last_name":
52 field_type = "NAME_LAST" 54 field_type = "NAME_LAST"
53 elif column_name == "full_name": 55 elif column_name == "full_name":
54 field_type = "NAME_FULL" 56 field_type = "NAME_FULL"
55 elif column_name == "email": 57 elif column_name == "email":
56 field_type = "EMAIL_ADDRESS" 58 field_type = "EMAIL_ADDRESS"
57 elif column_name == "company_name": 59 elif column_name == "company_name":
58 field_type = "COMPANY_NAME" 60 field_type = "COMPANY_NAME"
59 elif column_name == "address_line_1": 61 elif column_name == "address_line_1":
60 field_type = "ADDRESS_HOME_LINE1" 62 field_type = "ADDRESS_HOME_LINE1"
61 elif column_name == "address_line_2": 63 elif column_name == "address_line_2":
62 field_type = "ADDRESS_HOME_LINE2" 64 field_type = "ADDRESS_HOME_LINE2"
63 elif column_name == "street_address": 65 elif column_name == "street_address":
64 field_type = "ADDRESS_HOME_STREET_ADDRESS" 66 field_type = "ADDRESS_HOME_STREET_ADDRESS"
65 elif column_name == "city": 67 elif column_name == "city":
66 field_type = "ADDRESS_HOME_CITY" 68 field_type = "ADDRESS_HOME_CITY"
67 elif column_name == "state": 69 elif column_name == "state":
68 field_type = "ADDRESS_HOME_STATE" 70 field_type = "ADDRESS_HOME_STATE"
69 elif column_name == "zipcode": 71 elif column_name == "zipcode":
70 field_type = "ADDRESS_HOME_ZIP" 72 field_type = "ADDRESS_HOME_ZIP"
71 elif column_name == "country_code": 73 elif column_name == "country_code":
72 field_type = "ADDRESS_HOME_COUNTRY" 74 field_type = "ADDRESS_HOME_COUNTRY"
73 elif column_name == "sorting_code":
74 field_type = "ADDRESS_HOME_SORTING_CODE"
75 elif column_name == "dependent_locality":
76 field_type = "ADDRESS_HOME_DEPENDENT_LOCALITY"
77 elif column_name == "phone": 75 elif column_name == "phone":
78 field_type = "PHONE_HOME_WHOLE_NUMBER" 76 field_type = "PHONE_HOME_WHOLE_NUMBER"
79 else: 77 else:
80 raise UnknownColumnNameException(column_name) 78 raise UnknownColumnNameException(column_name)
81 79
82 return field_type 80 return field_type
OLDNEW
« no previous file with comments | « components/test/data/autofill/merge/output/validation.out ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698