Changeset 8466 for main/waeup.kofa/trunk/src/waeup/kofa/utils/tests
- Timestamp:
- 17 May 2012, 16:30:02 (13 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa/utils/tests
- Files:
-
- 3 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/utils/tests/test_helpers.py
r8369 r8466 317 317 return 318 318 319 class GetFileFormatTestCase(unittest.TestCase): 320 # Tests for the get_fileformat helper. 321 322 def setUp(self): 323 self.valid_jpg_path = os.path.join( 324 os.path.dirname(__file__), 'sample_jpg_valid.jpg') 325 self.valid_jpg = open(self.valid_jpg_path, 'rb').read() 326 self.valid_png_path = os.path.join( 327 os.path.dirname(__file__), 'sample_png_valid.png') 328 self.valid_png = open(self.valid_png_path, 'rb').read() 329 self.valid_pdf_path = os.path.join( 330 os.path.dirname(__file__), 'sample_pdf_valid.pdf') 331 self.valid_pdf = open(self.valid_pdf_path, 'rb').read() 332 return 333 334 def test_none(self): 335 # ``None`` is not a file and not a valid file format 336 self.assertEqual(helpers.get_fileformat(None), None) 337 return 338 339 def test_path_and_bytestream(self): 340 # get_fileformat accepts bytestreams and paths as arg. 341 self.assertEqual( 342 helpers.get_fileformat(None, self.valid_jpg), 'jpg') 343 self.assertEqual( 344 helpers.get_fileformat(self.valid_jpg_path), 'jpg') 345 # path is ignored when giving a bytestream 346 self.assertEqual( 347 helpers.get_fileformat('blah', self.valid_jpg), 'jpg') 348 return 349 350 def test_jpg(self): 351 # we recognize jpeg images. 352 self.assertEqual( 353 helpers.get_fileformat(self.valid_jpg_path), 'jpg') 354 self.assertEqual( 355 helpers.get_fileformat(None, self.valid_jpg), 'jpg') 356 return 357 358 def test_png(self): 359 # we recognize png images. 360 self.assertEqual( 361 helpers.get_fileformat(self.valid_png_path), 'png') 362 self.assertEqual( 363 helpers.get_fileformat(None, self.valid_png), 'png') 364 return 365 366 def test_pdf(self): 367 # we recognize pdf documents. 368 self.assertEqual( 369 helpers.get_fileformat(self.valid_pdf_path), 'pdf') 370 self.assertEqual( 371 helpers.get_fileformat(None, self.valid_pdf), 'pdf') 372 return 373 319 374 def test_suite(): 320 375 suite = unittest.TestSuite() … … 330 385 IfaceNamesTestCase, 331 386 DateTimeHelpersTestCase, 387 GetFileFormatTestCase, 332 388 ]: 333 389 suite.addTests(
Note: See TracChangeset for help on using the changeset viewer.