1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# imports
import operator
import unittest
# bsfs imports
from bsfs.utils import URI
# objects to test
from bsfs.namespace.namespace import Namespace, FinalNamespace
## code ##
class TestNamespace(unittest.TestCase):
def test_essentials(self):
# string conversion
self.assertEqual(str(Namespace('http://example.org')), 'http://example.org')
self.assertEqual(repr(Namespace('http://example.org')), "'http://example.org'")
# comparison
self.assertEqual(Namespace('http://example.org'), Namespace('http://example.org'))
self.assertEqual(hash(Namespace('http://example.org')), hash(Namespace('http://example.org')))
# Namespace compares to string
self.assertEqual(Namespace('http://example.org'), 'http://example.org')
self.assertEqual(hash(Namespace('http://example.org')), hash('http://example.org'))
# URI must match
self.assertNotEqual(Namespace('http://example.org'), Namespace('http://example.com'))
self.assertNotEqual(hash(Namespace('http://example.org')), hash(Namespace('http://example.com')))
def test_getattr(self):
self.assertEqual(Namespace('http://example.org').foo, Namespace('http://example.org/foo'))
self.assertEqual(Namespace('http://example.org').bar, Namespace('http://example.org/bar'))
def test_call(self):
self.assertEqual(Namespace('http://example.org')(), FinalNamespace('http://example.org', sep='#'))
self.assertEqual(Namespace('http://example.org').foo(), FinalNamespace('http://example.org/foo', sep='#'))
class TestFinalNamespace(unittest.TestCase):
def test_essentials(self):
# string conversion
self.assertEqual(str(FinalNamespace('http://example.org')), 'http://example.org')
self.assertEqual(repr(FinalNamespace('http://example.org')), "'http://example.org'")
# comparison
self.assertEqual(FinalNamespace('http://example.org'), FinalNamespace('http://example.org'))
self.assertEqual(hash(FinalNamespace('http://example.org')), hash(FinalNamespace('http://example.org')))
# FinalNamespace compares to string
self.assertEqual(FinalNamespace('http://example.org'), 'http://example.org')
self.assertEqual(hash(FinalNamespace('http://example.org')), hash('http://example.org'))
# URI must match
self.assertNotEqual(FinalNamespace('http://example.org'), FinalNamespace('http://example.com'))
self.assertNotEqual(hash(FinalNamespace('http://example.org')), hash(FinalNamespace('http://example.com')))
# separator is ignored
self.assertEqual(FinalNamespace('http://example.org'), FinalNamespace('http://example.org', sep='/'))
self.assertEqual(hash(FinalNamespace('http://example.org')), hash(FinalNamespace('http://example.org', sep='/')))
def test_getattr(self):
self.assertEqual(FinalNamespace('http://example.org').foo, FinalNamespace('http://example.org#foo'))
self.assertEqual(FinalNamespace('http://example.org').bar, FinalNamespace('http://example.org#bar'))
self.assertEqual(FinalNamespace('http://example.org', sep='/').bar, FinalNamespace('http://example.org/bar'))
## main ##
if __name__ == '__main__':
unittest.main()
## EOF ##
|