1212
1313
1414class Fauxku (Roku ):
15-
1615 def __init__ (self , * args , ** kwargs ):
1716 super (Fauxku , self ).__init__ (* args , ** kwargs )
1817 self ._calls = []
1918
2019 def _call (self , method , path , * args , ** kwargs ):
2120 self ._calls .append ((method , path , args , kwargs ))
22- return ''
21+ return ""
2322
2423 def calls (self ):
2524 return self ._calls
@@ -30,38 +29,36 @@ def last_call(self):
3029
3130@pytest .fixture
3231def roku ():
33- return Fauxku (' 0.0.0.0' )
32+ return Fauxku (" 0.0.0.0" )
3433
3534
3635@pytest .fixture
3736def apps (roku ):
3837 faux_apps = [
39- Application ('11' , ' 1.0.1' , ' Fauxku Channel Store' , roku ),
40- Application ('22' , ' 2.0.2' , ' Faux Netflix' , roku ),
41- Application ('33' , ' 3.0.3' , ' Faux YouTube' , roku ),
42- Application (' 44HL' , ' 4.0.4' , ' Faux Hulu' , roku ),
38+ Application ("11" , " 1.0.1" , " Fauxku Channel Store" , roku ),
39+ Application ("22" , " 2.0.2" , " Faux Netflix" , roku ),
40+ Application ("33" , " 3.0.3" , " Faux YouTube" , roku ),
41+ Application (" 44HL" , " 4.0.4" , " Faux Hulu" , roku ),
4342 ]
4443 return faux_apps
4544
4645
4746def test_apps (mocker , roku ):
47+ faux_apps = (Application ("0x" , "1.2.3" , "Fauxku Channel Store" ),)
4848
49- faux_apps = (Application ('0x' , '1.2.3' , 'Fauxku Channel Store' ),)
50-
51- mocked_get = mocker .patch .object (Roku , '_get' )
49+ mocked_get = mocker .patch .object (Roku , "_get" )
5250 mocked_get .return_value = serialize_apps (faux_apps )
5351
5452 apps = roku .apps
5553
5654 assert len (apps ) == 1
57- assert apps [0 ].id == '0x'
58- assert apps [0 ].version == ' 1.2.3'
59- assert apps [0 ].name == ' Fauxku Channel Store'
55+ assert apps [0 ].id == "0x"
56+ assert apps [0 ].version == " 1.2.3"
57+ assert apps [0 ].name == " Fauxku Channel Store"
6058
6159
6260def test_app_selector (mocker , apps ):
63-
64- mocked_get = mocker .patch .object (Roku , '_get' )
61+ mocked_get = mocker .patch .object (Roku , "_get" )
6562 mocked_get .return_value = serialize_apps (apps )
6663
6764 for app in apps :
@@ -71,113 +68,99 @@ def test_app_selector(mocker, apps):
7168
7269
7370def test_device_info (mocker , roku ):
74-
75- xml_path = os .path .join (TESTS_PATH , 'responses' , 'device-info.xml' )
71+ xml_path = os .path .join (TESTS_PATH , "responses" , "device-info.xml" )
7672 with open (xml_path ) as infile :
7773 content = infile .read ()
7874
79- mocked_get = mocker .patch .object (Roku , ' _get' )
80- mocked_get .return_value = content .encode (' utf-8' )
75+ mocked_get = mocker .patch .object (Roku , " _get" )
76+ mocked_get .return_value = content .encode (" utf-8" )
8177
8278 d = roku .device_info
8379
84- assert d .model_name == ' Roku 3'
85- assert d .model_num == ' 4200X'
86- assert d .software_version == ' 7.00.09044'
87- assert d .serial_num == ' 111111111111'
88- assert d .roku_type == ' Stick'
80+ assert d .model_name == " Roku 3"
81+ assert d .model_num == " 4200X"
82+ assert d .software_version == " 7.00.09044"
83+ assert d .serial_num == " 111111111111"
84+ assert d .roku_type == " Stick"
8985
9086
9187def test_media_player (mocker , roku ):
92-
93- xml_path = os .path .join (TESTS_PATH , 'responses' , 'media-player.xml' )
88+ xml_path = os .path .join (TESTS_PATH , "responses" , "media-player.xml" )
9489 with open (xml_path ) as infile :
9590 content = infile .read ()
9691
97- faux_apps = (Application (33 , ' 1.2.3' , ' Faux YouTube' ),)
92+ faux_apps = (Application (33 , " 1.2.3" , " Faux YouTube" ),)
9893
99- mocked_get = mocker .patch .object (Roku , ' _get' )
100- mocked_get .return_value = content .encode (' utf-8' )
101- mocker .patch .object (Roku , ' apps' , new = faux_apps )
94+ mocked_get = mocker .patch .object (Roku , " _get" )
95+ mocked_get .return_value = content .encode (" utf-8" )
96+ mocker .patch .object (Roku , " apps" , new = faux_apps )
10297
10398 m = roku .media_player
10499
105- assert m .state == ' pause'
106- assert m .app .name == ' Faux YouTube'
100+ assert m .state == " pause"
101+ assert m .app .name == " Faux YouTube"
107102 assert m .position == 11187
108103 assert m .duration == 1858000
109104
110105
111106def test_commands (roku ):
112-
113107 for cmd in roku .commands :
114-
115- if cmd in ['literal' , 'search' ]:
108+ if cmd in ["literal" , "search" ]:
116109 # there is a separate test for the literal and search command
117110 continue
118111
119112 getattr (roku , cmd )()
120113 call = roku .last_call ()
121114
122- assert call == (' POST' , f' /keypress/{ COMMANDS [cmd ]} ' , (), {})
115+ assert call == (" POST" , f" /keypress/{ COMMANDS [cmd ]} " , (), {})
123116
124117
125118def test_search (roku ):
126-
127- text = 'Stargate'
119+ text = "Stargate"
128120 roku .search (title = text )
129121
130122 call = roku .last_call ()
131123
132- assert call == (' POST' , ' /search/browse' , (), {' params' : {' title' : text }})
124+ assert call == (" POST" , " /search/browse" , (), {" params" : {" title" : text }})
133125
134126
135127def test_literal (roku ):
136-
137- text = 'Stargate'
128+ text = "Stargate"
138129 roku .literal (text )
139130
140131 for i , call in enumerate (roku .calls ()):
141- assert call == (
142- 'POST' , f'/keypress/Lit_{ quote_plus (text [i ])} ' , (), {})
132+ assert call == ("POST" , f"/keypress/Lit_{ quote_plus (text [i ])} " , (), {})
143133
144134
145135def test_literal_fancy (roku ):
146-
147136 text = r"""~!@#$%^&*()_+`-=[]{};':",./<>?\|€£"""
148137 roku .literal (text )
149138
150139 for i , call in enumerate (roku .calls ()):
151- assert call == (
152- 'POST' , f'/keypress/Lit_{ quote_plus (text [i ])} ' , (), {})
140+ assert call == ("POST" , f"/keypress/Lit_{ quote_plus (text [i ])} " , (), {})
153141
154142
155143def test_store (apps ):
156-
157144 for app in apps :
158-
159145 roku = app .roku
160146 roku .store (app )
161147 call = roku .last_call ()
162148
163- params = {' params' : {' contentID' : app .id }}
164- assert call == (' POST' , ' /launch/11' , (), params )
149+ params = {" params" : {" contentID" : app .id }}
150+ assert call == (" POST" , " /launch/11" , (), params )
165151
166152
167153def test_launch (apps ):
168-
169154 for app in apps :
170-
171155 roku = app .roku
172156 roku .launch (app )
173157 call = roku .last_call ()
174158
175- params = {' params' : {' contentID' : app .id }}
176- assert call == (' POST' , f' /launch/{ app .id } ' , (), params )
159+ params = {" params" : {" contentID" : app .id }}
160+ assert call == (" POST" , f" /launch/{ app .id } " , (), params )
177161
178162
179163def test_icon_url (apps ):
180-
181164 for app in apps :
182165 assert app .roku .icon_url (app ) == f"http://0.0.0.0:8060/query/icon/{ app .id } "
183166 assert app .icon_url == f"http://0.0.0.0:8060/query/icon/{ app .id } "
0 commit comments