當前位置: 首頁>>代碼示例>>Python>>正文


Python Space.get方法代碼示例

本文整理匯總了Python中space.Space.get方法的典型用法代碼示例。如果您正苦於以下問題:Python Space.get方法的具體用法?Python Space.get怎麽用?Python Space.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在space.Space的用法示例。


在下文中一共展示了Space.get方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: testDeepCopy

# 需要導入模塊: from space import Space [as 別名]
# 或者: from space.Space import get [as 別名]
 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')
開發者ID:breck7,項目名稱:spacepython,代碼行數:13,代碼來源:test_space.py

示例2: test_multiline

# 需要導入模塊: from space import Space [as 別名]
# 或者: from space.Space import get [as 別名]
    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')
開發者ID:jyxt,項目名稱:spacepython,代碼行數:15,代碼來源:test_space.py

示例3: test_append

# 需要導入模塊: from space import Space [as 別名]
# 或者: from space.Space import get [as 別名]
 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)
開發者ID:jyxt,項目名稱:spacepython,代碼行數:9,代碼來源:test_space.py

示例4: test_set

# 需要導入模塊: from space import Space [as 別名]
# 或者: from space.Space import get [as 別名]
 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')
開發者ID:jyxt,項目名稱:spacepython,代碼行數:19,代碼來源:test_space.py

示例5: testMultiLine

# 需要導入模塊: from space import Space [as 別名]
# 或者: from space.Space import get [as 別名]
    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')
開發者ID:breck7,項目名稱:spacepython,代碼行數:26,代碼來源:test_space.py

示例6: testClearWithSpaceArgument

# 需要導入模塊: from space import Space [as 別名]
# 或者: from space.Space import get [as 別名]
 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')
開發者ID:breck7,項目名稱:spacepython,代碼行數:7,代碼來源:test_space.py

示例7: testLength

# 需要導入模塊: from space import Space [as 別名]
# 或者: from space.Space import get [as 別名]
 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')
開發者ID:breck7,項目名稱:spacepython,代碼行數:6,代碼來源:test_space.py

示例8: testPathNotExist

# 需要導入模塊: from space import Space [as 別名]
# 或者: from space.Space import get [as 別名]
 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')
開發者ID:breck7,項目名稱:spacepython,代碼行數:5,代碼來源:test_space.py

示例9: testKeyNotExist

# 需要導入模塊: from space import Space [as 別名]
# 或者: from space.Space import get [as 別名]
 def testKeyNotExist(self):
     space = Space('foobar\n leaf 1')
     self.assertEqual(space.get('Hi'), None, 'Should return None if key does not exist')
開發者ID:breck7,項目名稱:spacepython,代碼行數:5,代碼來源:test_space.py

示例10: testNestSpace

# 需要導入模塊: from space import Space [as 別名]
# 或者: from space.Space import get [as 別名]
 def testNestSpace(self):
     space = Space('foobar\n one 1')
     self.assertTrue(isinstance(space.get('foobar'), Space), 'Nested space should be Space type')
開發者ID:breck7,項目名稱:spacepython,代碼行數:5,代碼來源:test_space.py

示例11: testGetSet

# 需要導入模塊: from space import Space [as 別名]
# 或者: from space.Space import get [as 別名]
 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' )
開發者ID:breck7,項目名稱:spacepython,代碼行數:8,代碼來源:test_space.py

示例12: testConcat

# 需要導入模塊: from space import Space [as 別名]
# 或者: from space.Space import get [as 別名]
 def testConcat(self):
     space1 = Space('hi world')
     b = Space('hello there')
     space1.concat(b)
     self.assertEqual(space1.get('hello'), 'there')
開發者ID:jyxt,項目名稱:spacepython,代碼行數:7,代碼來源:test_space.py


注:本文中的space.Space.get方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。