Skip to content

Commit 043a476

Browse files
committed
Initial commit of unit test for CSV parsing submodule
Check whether or not YAML files and CSV files containing the same data produce equivalent Contact objects. Make one of the CSV files 'jumbled' to show that column order doesn't matter to getting the right result.
1 parent 3fc56ae commit 043a476

7 files changed

Lines changed: 535 additions & 1 deletion

File tree

khard/khard.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ def new_subcommand(abooks: AddressBookCollection, fmt: str, delimiter: str,
451451
if fmt == 'yaml':
452452
create_new_contact(abook)
453453
elif fmt == 'csv':
454-
create_new_contacts(abook)
454+
create_new_contacts(abook, delimiter)
455455

456456

457457
def add_email_to_contact(name: str, email_address: str,

test/fixture/csv/batman.yaml

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
# Contact template for khard version 0.1.dev1192+g40c9de648
2+
#
3+
# Use this yaml formatted template to create a new contact:
4+
# either with: khard new -a address_book -i template.yaml
5+
# or with: cat template.yaml | khard new -a address_book
6+
7+
# Every contact must contain a formatted name, it will be autofilled
8+
# from the full name below if not given.
9+
Formatted name :
10+
11+
# kind (requires vcard 4.0)
12+
# one of: individual, group, org, location, application, device
13+
Kind :
14+
15+
# name components
16+
# every entry may contain a string or a list of strings
17+
# format:
18+
# First name : name1
19+
# Additional :
20+
# - name2
21+
# - name3
22+
# Last name : name4
23+
Prefix :
24+
First name : Bruce
25+
Additional :
26+
Last name : Wayne
27+
Suffix :
28+
29+
# nickname
30+
# may contain a string or a list of strings
31+
Nickname : Batman
32+
33+
# important dates
34+
# Formats:
35+
# vcard 3.0 and 4.0: yyyy-mm-dd or yyyy-mm-ddTHH:MM:SS
36+
# vcard 4.0 only: --mm-dd or text= string value
37+
# anniversary
38+
Anniversary :
39+
# birthday
40+
Birthday :
41+
42+
# organisation
43+
# format:
44+
# Organisation : company
45+
# or
46+
# Organisation :
47+
# - company1
48+
# - company2
49+
# or
50+
# Organisation :
51+
# -
52+
# - company
53+
# - unit
54+
Organisation :
55+
- Justice League
56+
- Wayne Enterprises
57+
58+
# organisation title and role
59+
# every entry may contain a string or a list of strings
60+
#
61+
# title at organisation
62+
# example usage: research scientist
63+
Title :
64+
# role at organisation
65+
# example usage: project leader
66+
Role :
67+
68+
# phone numbers
69+
# format:
70+
# Phone:
71+
# type1, type2: number
72+
# type3:
73+
# - number1
74+
# - number2
75+
# custom: number
76+
# allowed types:
77+
# vcard 3.0: At least one of bbs, car, cell, fax, home, isdn, msg, modem,
78+
# pager, pcs, pref, video, voice, work
79+
# vcard 4.0: At least one of home, work, pref, text, voice, fax, cell, video,
80+
# pager, textphone
81+
# Alternatively you may use a single custom label (only letters).
82+
# But beware, that not all address book clients will support custom labels.
83+
Phone :
84+
cell : 911
85+
home :
86+
87+
# email addresses
88+
# format like phone numbers above
89+
# allowed types:
90+
# vcard 3.0: At least one of home, internet, pref, work, x400
91+
# vcard 4.0: At least one of home, internet, pref, work
92+
# Alternatively you may use a single custom label (only letters).
93+
Email :
94+
home : batman39@dc.com
95+
work :
96+
- thebat@justice.org
97+
- bruce@wayne.com
98+
99+
# post addresses
100+
# allowed types:
101+
# vcard 3.0: At least one of dom, intl, home, parcel, postal, pref, work
102+
# vcard 4.0: At least one of home, pref, work
103+
# Alternatively you may use a single custom label (only letters).
104+
Address :
105+
work :
106+
-
107+
Box :
108+
Extended : Hall of Justice
109+
Street :
110+
Code :
111+
City : Washington D.C.
112+
Region :
113+
Country : USA
114+
-
115+
Box :
116+
Extended : Wayne Enterprises
117+
Street :
118+
Code :
119+
City : Gotham City
120+
Region :
121+
Country : USA
122+
home :
123+
Box :
124+
Extended :
125+
Street : 1007 Mountain Drive
126+
Code :
127+
City : Gotham City
128+
Region :
129+
Country : USA
130+
131+
# categories or tags
132+
# format:
133+
# Categories : single category
134+
# or
135+
# Categories :
136+
# - category1
137+
# - category2
138+
Categories :
139+
140+
# web pages
141+
# may contain a string or a list of strings
142+
Webpage :
143+
144+
# private objects
145+
# define your own private objects in the vcard section of your khard config file
146+
# example:
147+
# [vcard]
148+
# private_objects = Jabber, Skype, Twitter
149+
# these objects are stored with a leading "X-" before the object name in the
150+
# vcard files.
151+
# every entry may contain a string or a list of strings
152+
Private :
153+
154+
# notes
155+
# may contain a string or a list of strings
156+
# for multi-line notes use:
157+
# Note : |
158+
# line one
159+
# line two
160+
Note :
161+

test/fixture/csv/jumbled.csv

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Prefix,Address 3 - type,Additional 2,Email 1 - value,Address 2 - City,Phone 2 - value,Address 1 - Country,Address 2 - type,Address 2 - Country,Address 1 - City,Webpage,Address 1 - type,Birthday,Formatted name,Address 2 - Extended,Address 3 - Country,Address 2 - Region,Categories 2,Address 3 - Region,Organisation 2,Address 1 - Region,Categories 1,Address 1 - Street,Role,Address 1 - Extended,Phone 2 - type,Address 1 - Box,Email 3 - type,Organisation 1,Title,Address 2 - Code,Anniversary,Nickname,Address 2 - Street,Additional 1,Address 3 - Street,Last name,Address 3 - Box,Email 3 - value,Phone 1 - type,Email 1 - type,Kind,Email 2 - value,Address 3 - Extended,Note,Email 2 - type,Address 2 - Box,Address 3 - City,First name,Suffix,Address 3 - Code,Phone 1 - value,Address 1 - Code
2+
,home,,thebat@justice.org,Gotham City,,USA,work,USA,Washington D.C.,,work,,,Wayne Enterprises,USA,,,,Wayne Enterprises,,,,,Hall of Justice,,,work,Justice League,,,,Batman,,,1007 Mountain Drive,Wayne,,bruce@wayne.com,cell,work,,batman39@dc.com,,,home,,Gotham City,Bruce,,,911,
3+
,home,,theman@justice.org,Metropolis,,USA,work,USA,Washington D.C.,,work,,,The Daily Planet,USA,,,,The Daily Planet,,,,,Hall of Justice,,,work,Justice League,,,,Superman,,,344 Clinton Street,Kent,,kent@dailyplanet.com,cell,work,,,,,,,Metropolis,Clark,,,911,
4+
,,,lane@dailyplanet.com,,,USA,,,Metropolis,,work,,,,,,,,,,,,,The Daily Planet,,,,The Daily Planet,,,,,,,,Lane,,,,work,,,,,,,,Lois,,,,

test/fixture/csv/lois_lane.yaml

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
# Contact template for khard version 0.1.dev1192+g40c9de648
2+
#
3+
# Use this yaml formatted template to create a new contact:
4+
# either with: khard new -a address_book -i template.yaml
5+
# or with: cat template.yaml | khard new -a address_book
6+
7+
# Every contact must contain a formatted name, it will be autofilled
8+
# from the full name below if not given.
9+
Formatted name :
10+
11+
# kind (requires vcard 4.0)
12+
# one of: individual, group, org, location, application, device
13+
Kind :
14+
15+
# name components
16+
# every entry may contain a string or a list of strings
17+
# format:
18+
# First name : name1
19+
# Additional :
20+
# - name2
21+
# - name3
22+
# Last name : name4
23+
Prefix :
24+
First name : Lois
25+
Additional :
26+
Last name : Lane
27+
Suffix :
28+
29+
# nickname
30+
# may contain a string or a list of strings
31+
Nickname :
32+
33+
# important dates
34+
# Formats:
35+
# vcard 3.0 and 4.0: yyyy-mm-dd or yyyy-mm-ddTHH:MM:SS
36+
# vcard 4.0 only: --mm-dd or text= string value
37+
# anniversary
38+
Anniversary :
39+
# birthday
40+
Birthday :
41+
42+
# organisation
43+
# format:
44+
# Organisation : company
45+
# or
46+
# Organisation :
47+
# - company1
48+
# - company2
49+
# or
50+
# Organisation :
51+
# -
52+
# - company
53+
# - unit
54+
Organisation : The Daily Planet
55+
56+
# organisation title and role
57+
# every entry may contain a string or a list of strings
58+
#
59+
# title at organisation
60+
# example usage: research scientist
61+
Title :
62+
# role at organisation
63+
# example usage: project leader
64+
Role :
65+
66+
# phone numbers
67+
# format:
68+
# Phone:
69+
# type1, type2: number
70+
# type3:
71+
# - number1
72+
# - number2
73+
# custom: number
74+
# allowed types:
75+
# vcard 3.0: At least one of bbs, car, cell, fax, home, isdn, msg, modem,
76+
# pager, pcs, pref, video, voice, work
77+
# vcard 4.0: At least one of home, work, pref, text, voice, fax, cell, video,
78+
# pager, textphone
79+
# Alternatively you may use a single custom label (only letters).
80+
# But beware, that not all address book clients will support custom labels.
81+
Phone :
82+
cell :
83+
home :
84+
85+
# email addresses
86+
# format like phone numbers above
87+
# allowed types:
88+
# vcard 3.0: At least one of home, internet, pref, work, x400
89+
# vcard 4.0: At least one of home, internet, pref, work
90+
# Alternatively you may use a single custom label (only letters).
91+
Email :
92+
home :
93+
work : lane@dailyplanet.com
94+
95+
# post addresses
96+
# allowed types:
97+
# vcard 3.0: At least one of dom, intl, home, parcel, postal, pref, work
98+
# vcard 4.0: At least one of home, pref, work
99+
# Alternatively you may use a single custom label (only letters).
100+
Address :
101+
work :
102+
Box :
103+
Extended : The Daily Planet
104+
Street :
105+
Code :
106+
City : Metropolis
107+
Region :
108+
Country : USA
109+
110+
# categories or tags
111+
# format:
112+
# Categories : single category
113+
# or
114+
# Categories :
115+
# - category1
116+
# - category2
117+
Categories :
118+
119+
# web pages
120+
# may contain a string or a list of strings
121+
Webpage :
122+
123+
# private objects
124+
# define your own private objects in the vcard section of your khard config file
125+
# example:
126+
# [vcard]
127+
# private_objects = Jabber, Skype, Twitter
128+
# these objects are stored with a leading "X-" before the object name in the
129+
# vcard files.
130+
# every entry may contain a string or a list of strings
131+
Private :
132+
133+
# notes
134+
# may contain a string or a list of strings
135+
# for multi-line notes use:
136+
# Note : |
137+
# line one
138+
# line two
139+
Note :
140+

test/fixture/csv/neat.csv

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Formatted name,Kind,Prefix,First name,Additional 1,Additional 2,Last name,Suffix,Nickname,Anniversary,Birthday,Organisation 1,Organisation 2,Title,Role,Phone 1 - type,Phone 1 - value,Phone 2 - type,Phone 2 - value,Email 1 - type,Email 1 - value,Email 2 - type,Email 2 - value,Email 3 - type,Email 3 - value,Address 1 - type,Address 1 - Box,Address 1 - Extended,Address 1 - Street,Address 1 - Code,Address 1 - City,Address 1 - Region,Address 1 - Country,Address 2 - type,Address 2 - Box,Address 2 - Extended,Address 2 - Street,Address 2 - Code,Address 2 - City,Address 2 - Region,Address 2 - Country,Address 3 - type,Address 3 - Box,Address 3 - Extended,Address 3 - Street,Address 3 - Code,Address 3 - City,Address 3 - Region,Address 3 - Country,Categories 1,Categories 2,Webpage,Note
2+
,,,Bruce,,,Wayne,,Batman,,,Justice League,Wayne Enterprises,,,cell,911,,,work,thebat@justice.org,home,batman39@dc.com,work,bruce@wayne.com,work,,Hall of Justice,,,Washington D.C.,,USA,work,,Wayne Enterprises,,,Gotham City,,USA,home,,,1007 Mountain Drive,,Gotham City,,USA,,,,
3+
,,,Clark,,,Kent,,Superman,,,Justice League,The Daily Planet,,,cell,911,,,work,theman@justice.org,,,work,kent@dailyplanet.com,work,,Hall of Justice,,,Washington D.C.,,USA,work,,The Daily Planet,,,Metropolis,,USA,home,,,344 Clinton Street,,Metropolis,,USA,,,,
4+
,,,Lois,,,Lane,,,,,The Daily Planet,,,,,,,,work,lane@dailyplanet.com,,,,,work,,The Daily Planet,,,Metropolis,,USA,,,,,,,,,,,,,,,,,,,,

0 commit comments

Comments
 (0)