test_llmanifest.py
上传用户:king477883
上传日期:2021-03-01
资源大小:9553k
文件大小:6k
源码类别:

游戏引擎

开发平台:

C++ Builder

  1. #!/usr/bin/python
  2. """
  3. @file test_llmanifest.py
  4. @author Ryan Williams
  5. @brief Test cases for LLManifest library.
  6. $LicenseInfo:firstyear=2006&license=viewergpl$
  7. Copyright (c) 2006-2010, Linden Research, Inc.
  8. Second Life Viewer Source Code
  9. The source code in this file ("Source Code") is provided by Linden Lab
  10. to you under the terms of the GNU General Public License, version 2.0
  11. ("GPL"), unless you have obtained a separate licensing agreement
  12. ("Other License"), formally executed by you and Linden Lab.  Terms of
  13. the GPL can be found in doc/GPL-license.txt in this distribution, or
  14. online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  15. There are special exceptions to the terms and conditions of the GPL as
  16. it is applied to this Source Code. View the full text of the exception
  17. in the file doc/FLOSS-exception.txt in this software distribution, or
  18. online at
  19. http://secondlifegrid.net/programs/open_source/licensing/flossexception
  20. By copying, modifying or distributing this software, you acknowledge
  21. that you have read and understood your obligations described above,
  22. and agree to abide by those obligations.
  23. ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  24. WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  25. COMPLETENESS OR PERFORMANCE.
  26. $/LicenseInfo$
  27. """
  28. from indra.util import llmanifest
  29. import os.path
  30. import os
  31. import unittest
  32. class DemoManifest(llmanifest.LLManifest):
  33.     def construct(self):
  34.         super(DemoManifest, self).construct()
  35.         if self.prefix("dir_1"):
  36.             self.path("test_a")
  37.             self.path(src="test_b", dst="test_dst_b")
  38.             self.path("*.test")
  39.             self.path("*.tex", "*.jpg")
  40.             if self.prefix("nested", dst=""):
  41.                 self.path("deep")
  42.                 self.end_prefix()
  43.             self.end_prefix("dir_1")
  44. class Demo_ArchManifest(llmanifest.LLManifest):
  45.         pass
  46. class TestLLManifest(unittest.TestCase):
  47.     mode='static'
  48.     def setUp(self):
  49.         self.m = llmanifest.LLManifest({'source':'src', 'dest':'dst', 'grid':'default', 'platform':'darwin', 'version':(1,2,3,4),
  50.                                         'artwork':'art', 'build':'build'})
  51.     def testproperwindowspath(self):
  52.         self.assertEqual(llmanifest.proper_windows_path("C:Program Files", "cygwin"),"/cygdrive/c/Program Files")
  53.         self.assertEqual(llmanifest.proper_windows_path("C:Program Files", "windows"), "C:Program Files")
  54.         self.assertEqual(llmanifest.proper_windows_path("/cygdrive/c/Program Files/NSIS", "windows"), "C:Program FilesNSIS")
  55.         self.assertEqual(llmanifest.proper_windows_path("/cygdrive/c/Program Files/NSIS", "cygwin"), "/cygdrive/c/Program Files/NSIS")
  56.     def testpathancestors(self):
  57.         self.assertEqual(["dir"], [p for p in llmanifest.path_ancestors("dir")])
  58.         self.assertEqual(["dir/sub", "dir"], [p for p in llmanifest.path_ancestors("dir/sub")])
  59.         self.assertEqual(["dir/sub", "dir"], [p for p in llmanifest.path_ancestors("dir/sub/")])
  60.         self.assertEqual(["dir/sub/two", "dir/sub", "dir"], [p for p in llmanifest.path_ancestors("dir/sub/two")])
  61.     def testforplatform(self):
  62.         self.assertEqual(llmanifest.LLManifest.for_platform('demo'), DemoManifest)
  63.         def tmp_test():
  64.             return llmanifest.LLManifest.for_platform('extant')
  65.         self.assertRaises(KeyError, tmp_test)
  66.         ExtantManifest = llmanifest.LLManifestRegistry('ExtantManifest', (llmanifest.LLManifest,), {})
  67.         self.assertEqual(llmanifest.LLManifest.for_platform('extant'), ExtantManifest)
  68.         self.assertEqual(llmanifest.LLManifest.for_platform('demo', 'Arch'), Demo_ArchManifest)
  69.     def testprefix(self):
  70.         self.assertEqual(self.m.get_src_prefix(), "src")
  71.         self.assertEqual(self.m.get_dst_prefix(), "dst")
  72.         self.m.prefix("level1")
  73.         self.assertEqual(self.m.get_src_prefix(), "src/level1")
  74.         self.assertEqual(self.m.get_dst_prefix(), "dst/level1")
  75.         self.m.end_prefix()
  76.         self.m.prefix(src="src", dst="dst")
  77.         self.assertEqual(self.m.get_src_prefix(), "src/src")
  78.         self.assertEqual(self.m.get_dst_prefix(), "dst/dst")
  79.         self.m.end_prefix()
  80.     def testendprefix(self):
  81.         self.assertEqual(self.m.get_src_prefix(), "src")
  82.         self.assertEqual(self.m.get_dst_prefix(), "dst")
  83.         self.m.prefix("levela")
  84.         self.m.end_prefix()
  85.         self.assertEqual(self.m.get_src_prefix(), "src")
  86.         self.assertEqual(self.m.get_dst_prefix(), "dst")
  87.         self.m.prefix("level1")
  88.         self.m.end_prefix("level1")
  89.         self.assertEqual(self.m.get_src_prefix(), "src")
  90.         self.assertEqual(self.m.get_dst_prefix(), "dst")
  91.         self.m.prefix("level1")
  92.         def tmp_test():
  93.             self.m.end_prefix("mismatch")
  94.         self.assertRaises(ValueError, tmp_test)
  95.     def testruncommand(self):
  96.         self.assertEqual("Hellon", self.m.run_command("echo Hello"))
  97.         def exit_1_test():
  98.             self.m.run_command("exit 1")
  99.         self.assertRaises(RuntimeError, exit_1_test)
  100.         def not_found_test():
  101.             self.m.run_command("test_command_that_should_not_be_found")
  102.         self.assertRaises(RuntimeError, not_found_test)
  103.     def testpathof(self):
  104.         self.assertEqual(self.m.src_path_of("a"), "src/a")
  105.         self.assertEqual(self.m.dst_path_of("a"), "dst/a")
  106.         self.m.prefix("tmp")
  107.         self.assertEqual(self.m.src_path_of("b/c"), "src/tmp/b/c")
  108.         self.assertEqual(self.m.dst_path_of("b/c"), "dst/tmp/b/c")
  109.     def testcmakedirs(self):
  110.         self.m.cmakedirs("test_dir_DELETE/nested/dir")
  111.         self.assert_(os.path.exists("test_dir_DELETE/nested/dir"))
  112.         self.assert_(os.path.isdir("test_dir_DELETE"))
  113.         self.assert_(os.path.isdir("test_dir_DELETE/nested"))
  114.         self.assert_(os.path.isdir("test_dir_DELETE/nested/dir"))
  115.         os.removedirs("test_dir_DELETE/nested/dir")
  116. if __name__ == '__main__':
  117.     unittest.main()