| 1 | # -*- Mode: Python; test-case-name: morituri.test.test_common_checksum -*- |
|---|
| 2 | # vi:si:et:sw=4:sts=4:ts=4 |
|---|
| 3 | |
|---|
| 4 | import os |
|---|
| 5 | import tempfile |
|---|
| 6 | |
|---|
| 7 | import gobject |
|---|
| 8 | gobject.threads_init() |
|---|
| 9 | |
|---|
| 10 | import gst |
|---|
| 11 | |
|---|
| 12 | from morituri.test import common |
|---|
| 13 | |
|---|
| 14 | from morituri.common import task, checksum, log, common |
|---|
| 15 | from morituri.image import image |
|---|
| 16 | |
|---|
| 17 | from morituri.test import common as tcommon |
|---|
| 18 | |
|---|
| 19 | def h(i): |
|---|
| 20 | return "0x%08x" % i |
|---|
| 21 | |
|---|
| 22 | class EmptyTestCase(tcommon.TestCase): |
|---|
| 23 | def testEmpty(self): |
|---|
| 24 | # this test makes sure that checksumming empty files doesn't hang |
|---|
| 25 | self.runner = task.SyncRunner(verbose=False) |
|---|
| 26 | fd, path = tempfile.mkstemp(suffix=u'morituri.test.empty') |
|---|
| 27 | checksumtask = checksum.ChecksumTask(path) |
|---|
| 28 | # FIXME: do we want a specific error for this ? |
|---|
| 29 | e = self.assertRaises(task.TaskException, self.runner.run, |
|---|
| 30 | checksumtask, verbose=False) |
|---|
| 31 | self.failUnless(isinstance(e.exception, checksum.GstException)) |
|---|
| 32 | os.unlink(path) |
|---|
| 33 | |
|---|
| 34 | class PathTestCase(tcommon.TestCase): |
|---|
| 35 | def _testSuffix(self, suffix): |
|---|
| 36 | self.runner = task.SyncRunner(verbose=False) |
|---|
| 37 | fd, path = tempfile.mkstemp(suffix=suffix) |
|---|
| 38 | checksumtask = checksum.ChecksumTask(path) |
|---|
| 39 | e = self.assertRaises(task.TaskException, self.runner.run, |
|---|
| 40 | checksumtask, verbose=False) |
|---|
| 41 | self.failUnless(isinstance(e.exception, checksum.GstException)) |
|---|
| 42 | os.unlink(path) |
|---|
| 43 | |
|---|
| 44 | class UnicodePathTestCase(PathTestCase, tcommon.UnicodeTestMixin): |
|---|
| 45 | def testUnicodePath(self): |
|---|
| 46 | # this test makes sure we can checksum a unicode path |
|---|
| 47 | self._testSuffix(u'morituri.test.B\xeate Noire.empty') |
|---|
| 48 | |
|---|
| 49 | class NormalPathTestCase(PathTestCase): |
|---|
| 50 | def testSingleQuote(self): |
|---|
| 51 | self._testSuffix(u"morituri.test.Guns 'N Roses") |
|---|
| 52 | |
|---|
| 53 | def testDoubleQuote(self): |
|---|
| 54 | # This test makes sure we can checksum files with double quote in |
|---|
| 55 | # their name |
|---|
| 56 | self._testSuffix(u'morituri.test.12" edit') |
|---|