diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2020-06-29 22:37:58 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2020-06-29 22:37:58 (GMT) |
commit | d3d57aa61bb44fd0bdad460c8c173743ca808733 (patch) | |
tree | a427000cc26a7af91b8a1b42e80aeddd4212edd4 /tests | |
parent | d436818deded4064c5476111f980189836b360c7 (diff) |
Improved some common helpers inside the Python API.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/common/fnv1a.py | 25 | ||||
-rw-r--r-- | tests/common/pathname.py | 33 |
2 files changed, 49 insertions, 9 deletions
diff --git a/tests/common/fnv1a.py b/tests/common/fnv1a.py new file mode 100644 index 0000000..2013afa --- /dev/null +++ b/tests/common/fnv1a.py @@ -0,0 +1,25 @@ + +from chrysacase import ChrysalideTestCase +from pychrysalide.common import fnv1a + + +class TestFnv1a(ChrysalideTestCase): + """TestCase for common.fnv1a*""" + + def testFnv1aConstructor(self): + """Check that no constructor is available for the fnv1a class.""" + + with self.assertRaisesRegex(NotImplementedError, 'Chrysalide does not allow building this kind of object from Python'): + instance = fnv1a() + + + def testFnv1aSamples(self): + """Compute some Fnv1a hashs.""" + + # Test cases from http://isthe.com/chongo/src/fnv/test_fnv.c + + val = fnv1a.hash('') + self.assertEqual(val, 0xcbf29ce484222325) + + val = fnv1a.hash('chongo was here!\n') + self.assertEqual(val, 0x46810940eff5f915) diff --git a/tests/common/pathname.py b/tests/common/pathname.py index 3692434..00a084b 100644 --- a/tests/common/pathname.py +++ b/tests/common/pathname.py @@ -1,21 +1,15 @@ -#!/usr/bin/python3-dbg -# -*- coding: utf-8 -*- - - -# Tests minimalistes pour valider la construction de chemins relatifs et absolus. - from chrysacase import ChrysalideTestCase from pychrysalide.common import pathname -class TestPathNames(ChrysalideTestCase): - """TestCase for common.pathname.build*""" +class TestPathnames(ChrysalideTestCase): + """TestCase for common.pathname*""" @classmethod def setUpClass(cls): - super(TestPathNames, cls).setUpClass() + super(TestPathnames, cls).setUpClass() cls._tests = [ { @@ -93,3 +87,24 @@ class TestPathNames(ChrysalideTestCase): with self.assertRaisesRegex(Exception, 'Relative path is too deep.'): got = build_absolute('/a/b', '../../c') + + + def testPathnameConstructor(self): + """Check that no constructor is available for the pathname class.""" + + with self.assertRaisesRegex(NotImplementedError, 'Chrysalide does not allow building this kind of object from Python'): + + instance = pathname() + + + def testPathnameSamples(self): + """Play with some path samples.""" + + filename = pathname.build_absolute_filename('/tmp/deep', '../myfile') + self.assertEqual(filename, '/myfile') + + filename = pathname.build_absolute_filename('/tmp/deep/', '../myfile') + self.assertEqual(filename, '/tmp/myfile') + + filename = pathname.build_relative_filename('/tmp/deep', '/myfile') + self.assertEqual(filename, '../myfile') |