コード例 #1
0
ファイル: test_space.py プロジェクト: breck7/spacepython
 def testDeepCopy(self):
     space1 = Space('hello world')
     space2 = space1.clone()
     self.assertEqual(space2.get('hello'), 'world', 'Clone should work')
     space2.set('hello', 'mom')
     self.assertEqual(space1.get('hello'), 'world', 'Clone makes deep copy')
     space3 = space1
     space3.set('hello', 'dad')
     self.assertEqual(space1.get('hello'), 'dad', '= makes shallow copy')
     space1.set('anotherSpace', Space('123 456'))
     self.assertEqual(space3.get('anotherSpace 123'), '456')
コード例 #2
0
ファイル: test_space.py プロジェクト: jyxt/spacepython
    def test_multiline(self):
        space = Space('my multiline\n string')
        self.assertEqual(space.get('my'), 'multiline\nstring')
        
        space2 = Space('my \n \n multiline\n string')
        self.assertEqual(space2.get('my'), '\n\nmultiline\nstring')

        space3 = Space('brave new\n world')
        self.assertEqual(space3.get('brave'), 'new\nworld', 'ml value correct')
        self.assertEqual(str(space3), 'brave new\n world\n', 'multiline does not begin with nl')

        space4 = Space('brave \n new\n world')
        self.assertEqual(space4.get('brave'), '\nnew\nworld', 'ml begin with nl value correct')
コード例 #3
0
ファイル: test_space.py プロジェクト: jyxt/spacepython
 def test_append(self):
     space = Space('hello world')
     space.append('foo', 'bar')
     space.set('foo2', 'bar')
     space.append('foo', 'two')
     self.assertEqual(space.get('foo'), 'bar')
     self.assertEqual(space.length(), 4)
コード例 #4
0
ファイル: test_space.py プロジェクト: jyxt/spacepython
 def test_set(self):
     space = Space('hello world')
     self.assertEqual(space.get('hello'), 'world')
     self.assertTrue(isinstance(space.set('hello', 'mom'), Space), 'set returns self for chaining')
     
     intSpace = Space()
     intSpace.set(2, 'hi')
     self.assertEqual(intSpace.get(2), 'hi')
     
     emptyStringSpace = Space()
     emptyStringSpace.set('boom', '')
     self.assertEqual(emptyStringSpace.get('boom'), '')
     
     # this is important, value should have been changed
     self.assertEqual(space.get('hello'), 'mom')
     space.set('head style color', 'blue')
     self.assertEqual(space.get('head style color'), 'blue')
コード例 #5
0
ファイル: test_space.py プロジェクト: breck7/spacepython
    def testMultiLine(self):
        string = 'user\n\
name Aristotle\n\
admin false\n\
stage\n\
name home\n\
domain test.test.com\n\
pro false\n\
domains\n\
 test.test.com\n\
  images\n\
  blocks\n\
  users\n\
  stage home\n\
  pages\n\
   home\n\
    settings\n\
     data\n\
      title Hello, World\n\
    block1\n\
     content Hello world\n'

        space = Space(string)
        self.assertEqual(space.get('domains test.test.com pages home settings data title'), 'Hello, World', 'Multiline creation shuold be OK')
コード例 #6
0
ファイル: test_space.py プロジェクト: breck7/spacepython
 def testClearWithSpaceArgument(self):
     space = Space("Hellow world")
     space.clear("hey there")
     self.assertEqual(space.length(), 1)
     self.assertEqual(space.get('hey'), 'there', 'Clear with a Space argument should deep copy the argument Space')
コード例 #7
0
ファイル: test_space.py プロジェクト: breck7/spacepython
 def testLength(self):
     space = Space('list\nsingle value')
     self.assertEqual(space.length(), 2, 'space should have 2 names')  # 'name' here means 'key'
     self.assertTrue(isinstance(space.get('list'), Space), 'name without a trailing space should be name')
コード例 #8
0
ファイル: test_space.py プロジェクト: breck7/spacepython
 def testPathNotExist(self):
     space = Space('Hello\n one 1\n two 2')
     self.assertEqual(space.get('Hello world one'), None, 'Should return None if path does not exist')
コード例 #9
0
ファイル: test_space.py プロジェクト: breck7/spacepython
 def testKeyNotExist(self):
     space = Space('foobar\n leaf 1')
     self.assertEqual(space.get('Hi'), None, 'Should return None if key does not exist')
コード例 #10
0
ファイル: test_space.py プロジェクト: breck7/spacepython
 def testNestSpace(self):
     space = Space('foobar\n one 1')
     self.assertTrue(isinstance(space.get('foobar'), Space), 'Nested space should be Space type')
コード例 #11
0
ファイル: test_space.py プロジェクト: breck7/spacepython
 def testGetSet(self):
     space = Space('Hello World')
     self.assertEqual(space.get("Hello"), 'World', 'Property should be accessible')
     self.assertEqual(type(space.get("Hello")), str, 'Leaf should be string')
     space.set('foo', 'bar')
     self.assertEqual(space.get('foo'), 'bar', 'Space should be modifiable' )
コード例 #12
0
ファイル: test_space.py プロジェクト: jyxt/spacepython
 def testConcat(self):
     space1 = Space('hi world')
     b = Space('hello there')
     space1.concat(b)
     self.assertEqual(space1.get('hello'), 'there')