3 ### Test atoms and related functionality
5 ### (c) 2019 Straylight/Edgeware
8 ###----- Licensing notice ---------------------------------------------------
10 ### This file is part of the Python interface to mLib.
12 ### mLib/Python is free software: you can redistribute it and/or modify it
13 ### under the terms of the GNU General Public License as published by the
14 ### Free Software Foundation; either version 2 of the License, or (at your
15 ### option) any later version.
17 ### mLib/Python is distributed in the hope that it will be useful, but
18 ### WITHOUT ANY WARRANTY; without even the implied warranty of
19 ### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 ### General Public License for more details.
22 ### You should have received a copy of the GNU General Public License
23 ### along with mLib/Python. If not, write to the Free Software
24 ### Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
31 ###--------------------------------------------------------------------------
32 class TestAtoms (U.TestCase):
37 me.assertTrue(foo is M.Atom("foo"))
38 me.assertTrue(foo is not bar)
39 me.assertEqual(foo, foo)
40 me.assertNotEqual(foo, bar)
41 me.assertEqual(set(M.atoms()), set([foo, bar]))
42 me.assertEqual(foo.name, "foo")
43 me.assertTrue(foo.internedp)
44 me.assertEqual(foo.home, M.DEFAULT_ATOMTABLE)
48 foo = tab.intern("foo")
49 bar = M.Atom("bar", tab)
51 g1 = M.Atom(table = tab)
52 me.assertEqual(bar, tab.intern("bar"))
53 me.assertNotEqual(foo, M.Atom("foo"))
54 for sym in [foo, bar, g0, g1]:
55 me.assertEqual(sym.home, tab)
56 me.assertTrue(sym.livep)
57 for sym in [foo, bar]: me.assertTrue(sym.internedp)
58 for sym in [g0, g1]: me.assertFalse(sym.internedp)
59 me.assertEqual(tab["foo"], foo)
60 me.assertEqual(tab.get("spong"), None)
61 me.assertFalse("spong" in tab)
63 me.assertTrue("spong" in tab)
64 me.assertEqual(set(T.itervalues(tab)), set([foo, bar, spong, g0, g1]))
66 for sym in [foo, bar, spong, g0, g1]: me.assertFalse(sym.livep)
67 me.assertRaises(ValueError, getattr, foo, "name")
71 me.assertRaises(TypeError, M.Atom, None, tab, foo = "extra!")
72 me.assertRaises(TypeError, M.Atom, table = tab, bar = "extra!")
73 me.assertRaises(TypeError, M.Atom, None, tab, "extra!")
74 me.assertTrue(a.livep)
76 me.assertFalse(a.livep)
79 ###--------------------------------------------------------------------------
80 class TestAssoc (T.MutableMappingTestMixin):
83 me._obarray = M.AtomTable()
85 def _mkkey(me, i): return me._obarray["k#%d" % i]
86 def _getkey(me, k): return int(k.name[2:])
89 me.check_mapping(lambda: M.AssocTable(None, me._obarray))
96 tab = M.AssocTable({ foo: 1 }, obarray, bar = 2)
97 me.assertEqual(tab.table, obarray)
98 me.assertEqual(tab["foo"], 1)
99 me.assertEqual(tab[bar], 2)
100 me.assertRaises(ValueError, tab.get, M.Atom("foo"))
102 ###----- That's all, folks --------------------------------------------------
104 if __name__ == "__main__": U.main()