~ubuntu-branches/ubuntu/natty/remuco/natty

« back to all changes in this revision

Viewing changes to base/module/test/testdictool.py

  • Committer: Bazaar Package Importer
  • Author(s): Chow Loong Jin
  • Date: 2009-08-18 23:06:11 UTC
  • Revision ID: james.westby@ubuntu.com-20090818230611-4z6ind4y4yxfa2z2
Tags: upstream-0.9.1.1
ImportĀ upstreamĀ versionĀ 0.9.1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# =============================================================================
 
2
#
 
3
#    Remuco - A remote control system for media players.
 
4
#    Copyright (C) 2006-2009 Oben Sonne <obensonne@googlemail.com>
 
5
#
 
6
#    This file is part of Remuco.
 
7
#
 
8
#    Remuco is free software: you can redistribute it and/or modify
 
9
#    it under the terms of the GNU General Public License as published by
 
10
#    the Free Software Foundation, either version 3 of the License, or
 
11
#    (at your option) any later version.
 
12
#
 
13
#    Remuco is distributed in the hope that it will be useful,
 
14
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
#    GNU General Public License for more details.
 
17
#
 
18
#    You should have received a copy of the GNU General Public License
 
19
#    along with Remuco.  If not, see <http://www.gnu.org/licenses/>.
 
20
#
 
21
# =============================================================================
 
22
 
 
23
import unittest
 
24
 
 
25
from remuco import dictool
 
26
 
 
27
class DicToolTest(unittest.TestCase):
 
28
 
 
29
 
 
30
    def setUp(self):
 
31
        pass
 
32
 
 
33
 
 
34
    def tearDown(self):
 
35
        pass
 
36
 
 
37
    def test_it(self):
 
38
        
 
39
        keys = ("a", "c", "b")
 
40
        dic1 = { "a": "1:d", "b": "2", "d": "4", "c": "3" }
 
41
        dic3 = { "a": "1", "b": "2,0", "d": "4", "c": "3" }
 
42
        
 
43
        flat = dictool.dict_to_string(dic1)
 
44
        dic2 = dictool.string_to_dict(flat)
 
45
        assert dic1 == dic2
 
46
        
 
47
        flat = dictool.dict_to_string(dic1, keys=keys)
 
48
        assert flat == "a:1:d,c:3,b:2"
 
49
        dic2 = dictool.string_to_dict(flat)
 
50
        assert dic1 != dic2
 
51
        
 
52
        flat = dictool.dict_to_string(dic3, keys=keys)
 
53
        assert flat == "a:1,c:3,b:2_0"
 
54
        
 
55
        l1 = [dic1,dic2]
 
56
        dictool.write_dicts_to_file("/var/tmp/dictest", l1, comment="# hallo")
 
57
        l2 = dictool.read_dicts_from_file("/var/tmp/dictest")
 
58
        assert l1 == l2
 
59
        
 
60
        dictool.write_dicts_to_file("/var/tmp/dictest", [dic1,dic2,dic3,flat],
 
61
                                    comment="# hallo", keys=["a"])
 
62
        l = dictool.read_dicts_from_file("/var/tmp/dictest")
 
63
        
 
64
        l = dictool.read_dicts_from_file("/var/tmp/non_existent")
 
65
        
 
66
if __name__ == "__main__":
 
67
    
 
68
    unittest.main()
 
 
b'\\ No newline at end of file'