Revision b3cb58c2 kamaki/cli/test.py
b/kamaki/cli/test.py  

42  42 
Argument, ConfigArgument, RuntimeConfigArgument, FlagArgument, 
43  43 
ValueArgument, IntArgument, DateArgument, VersionArgument, 
44  44 
KeyValueArgument, ProgressBarArgument, ArgumentParseManager) 
45 
from kamaki.cli.utils.test import UtilsMethods 

45  46  
46  47  
47  48 
class History(TestCase): 
...  ...  
279  280 
GL.assert_called_once_with('my logger name') 
280  281  
281  282  
282 
class UtilsMethods(TestCase): 

283  
284 
def assert_dicts_are_equal(self, d1, d2): 

285 
for k, v in d1.items(): 

286 
self.assertTrue(k in d2) 

287 
if isinstance(v, dict): 

288 
self.assert_dicts_are_equal(v, d2[k]) 

289 
else: 

290 
self.assertEqual(unicode(v), unicode(d2[k])) 

291  
292 
def test_guess_mime_type(self): 

293 
from kamaki.cli.utils import guess_mime_type 

294 
from mimetypes import guess_type 

295 
for args in product( 

296 
('file.txt', 'file.png', 'file.zip', 'file.gz', None, 'X'), 

297 
('a type', None), 

298 
('an/encoding', None)): 

299 
filename, ctype, cencoding = args 

300 
if filename: 

301 
exp_type, exp_enc = guess_type(filename) 

302 
self.assertEqual( 

303 
guess_mime_type(*args), 

304 
(exp_type or ctype, exp_enc or cencoding)) 

305 
else: 

306 
self.assertRaises(AssertionError, guess_mime_type, *args) 

307  
308 
def test_pretty_keys(self): 

309 
from kamaki.cli.utils import pretty_keys 

310 
for args, exp in ( 

311 
( 

312 
({'k1': 'v1', 'k1_k2': 'v2'}, ), 

313 
{'k1': 'v1', 'k1 k2': 'v2'}), 

314 
( 

315 
({'k1': 'v1', 'k1_k2': 'v2'}, '1'), 

316 
{'k': 'v1', 'k _k2': 'v2'}), 

317 
( 

318 
({'k1_k2': 'v1', 'k1': {'k2': 'v2', 'k2_k3': 'v3'}}, ), 

319 
{'k1 k2': 'v1', 'k1': {'k2': 'v2', 'k2_k3': 'v3'}}), 

320 
( 

321 
( 

322 
{'k1_k2': 'v1', 'k1': {'k2': 'v2', 'k2_k3': 'v3'}}, 

323 
'_', 

324 
True), 

325 
{'k1 k2': 'v1', 'k1': {'k2': 'v2', 'k2 k3': 'v3'}}), 

326 
( 

327 
( 

328 
{ 

329 
'k1_k2': {'k_1': 'v_1', 'k_2': {'k_3': 'v_3'}}, 

330 
'k1': {'k2': 'v2', 'k2_k3': 'v3'}}, 

331 
'_', 

332 
True), 

333 
{ 

334 
'k1 k2': {'k 1': 'v_1', 'k 2': {'k 3': 'v_3'}}, 

335 
'k1': {'k2': 'v2', 'k2 k3': 'v3'}}), 

336 
( 

337 
( 

338 
{ 

339 
'k1_k2': {'k_1': 'v_1', 'k_2': {'k_3': 'v_3'}}, 

340 
'k1': {'k2': 'v2', 'k2_k3': 'v3'}}, 

341 
'1', 

342 
True), 

343 
{ 

344 
'k _k2': {'k_': 'v_1', 'k_2': {'k_3': 'v_3'}}, 

345 
'k': {'k2': 'v2', 'k2_k3': 'v3'}}) 

346 
): 

347 
initial = dict(args[0]) 

348 
self.assert_dicts_are_equal(pretty_keys(*args), exp) 

349 
self.assert_dicts_are_equal(initial, args[0]) 

350  
351  
352  283 
# TestCase auxiliary methods 
353  284  
354  285 
def runTestCase(cls, test_name, args=[], failure_collector=[]): 
Also available in: Unified diff