1#!/usr/bin/env python 2# -*- coding: utf-8 -*- 3 4# 5# Copyright 2017, Data61 6# Commonwealth Scientific and Industrial Research Organisation (CSIRO) 7# ABN 41 687 119 230. 8# 9# This software may be distributed and modified according to the terms of 10# the BSD 2-Clause license. Note that NO WARRANTY is provided. 11# See "LICENSE_BSD2.txt" for details. 12# 13# @TAG(DATA61_BSD) 14# 15 16from __future__ import absolute_import, division, print_function, \ 17 unicode_literals 18 19import os, sys, unittest 20 21ME = os.path.abspath(__file__) 22 23# Make CAmkES importable 24sys.path.append(os.path.join(os.path.dirname(ME), '../../..')) 25 26from camkes.internal.frozendict import frozendict 27from camkes.internal.tests.utils import CAmkESTest 28 29class TestFrozenDict(CAmkESTest): 30 def test_construction(self): 31 d = frozendict() 32 self.assertIsNone(d.get('hello')) 33 34 d = frozendict({'hello':'world'}) 35 self.assertEqual(d['hello'], 'world') 36 37 def test_immutable(self): 38 d = frozendict() 39 40 with self.assertRaises(Exception): 41 d['hello'] = 'world' 42 43 d = frozendict({'hello':'world'}) 44 45 with self.assertRaises(Exception): 46 d['hello'] = 'world' 47 48if __name__ == '__main__': 49 unittest.main() 50