@@ -13,33 +13,29 @@ def setUp(self):
13
13
14
14
def get_login_credentials (self , user_type ):
15
15
# Example of parsing data from a file
16
- f = open ('qa_login_example.txt' , "r" )
17
- file_data = f .read ()
18
- file_lines = file_data .split ('\n ' )
19
- for line in file_lines :
20
- line_items = line .split (',' )
21
- if line_items [0 ] == user_type :
22
- return line_items [1 ], line_items [2 ]
23
- f .close ()
16
+ with open ('qa_login_example.txt' ) as f :
17
+ file_lines = [line .rstrip () for line in f ]
18
+ for line in file_lines :
19
+ line_items = line .split (',' )
20
+ if line_items [0 ] == user_type :
21
+ return line_items [1 ], line_items [2 ]
24
22
25
23
def get_all_login_credentials (self ):
26
24
# Example of parsing data from a file (Method 2)
27
25
keys = {}
28
- f = open ("staging_login_example.txt" )
29
- file_data = f .read ()
30
- file_lines = file_data .split ('\n ' )
31
- for line in file_lines :
32
- line_items = line .split (',' )
33
- if line_items [0 ] == 'admin' :
34
- keys ['admin' ] = (
35
- {'username' : line_items [1 ], 'password' : line_items [2 ]})
36
- if line_items [0 ] == 'employee' :
37
- keys ['employee' ] = (
38
- {'username' : line_items [1 ], 'password' : line_items [2 ]})
39
- if line_items [0 ] == 'customer' :
40
- keys ['customer' ] = (
41
- {'username' : line_items [1 ], 'password' : line_items [2 ]})
42
- f .close ()
26
+ with open ('staging_login_example.txt' ) as f :
27
+ file_lines = [line .rstrip () for line in f ]
28
+ for line in file_lines :
29
+ line_items = line .split (',' )
30
+ if line_items [0 ] == 'admin' :
31
+ keys ['admin' ] = (
32
+ {'username' : line_items [1 ], 'password' : line_items [2 ]})
33
+ if line_items [0 ] == 'employee' :
34
+ keys ['employee' ] = (
35
+ {'username' : line_items [1 ], 'password' : line_items [2 ]})
36
+ if line_items [0 ] == 'customer' :
37
+ keys ['customer' ] = (
38
+ {'username' : line_items [1 ], 'password' : line_items [2 ]})
43
39
return keys
44
40
45
41
0 commit comments