PageRenderTime 50ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/test/test_llmanifest.py

https://bitbucket.org/lindenlab/viewer-beta/
Python | 134 lines | 105 code | 2 blank | 27 comment | 2 complexity | c7d55e5ab020602c238fe2937285b31a MD5 | raw file
Possible License(s): LGPL-2.1
  1. #!/usr/bin/env python
  2. """
  3. @file test_llmanifest.py
  4. @author Ryan Williams
  5. @brief Test cases for LLManifest library.
  6. $LicenseInfo:firstyear=2006&license=viewerlgpl$
  7. Second Life Viewer Source Code
  8. Copyright (C) 2010, Linden Research, Inc.
  9. This library is free software; you can redistribute it and/or
  10. modify it under the terms of the GNU Lesser General Public
  11. License as published by the Free Software Foundation;
  12. version 2.1 of the License only.
  13. This library 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 GNU
  16. Lesser General Public License for more details.
  17. You should have received a copy of the GNU Lesser General Public
  18. License along with this library; if not, write to the Free Software
  19. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  21. $/LicenseInfo$
  22. """
  23. from indra.util import llmanifest
  24. import os.path
  25. import os
  26. import unittest
  27. class DemoManifest(llmanifest.LLManifest):
  28. def construct(self):
  29. super(DemoManifest, self).construct()
  30. if self.prefix("dir_1"):
  31. self.path("test_a")
  32. self.path(src="test_b", dst="test_dst_b")
  33. self.path("*.test")
  34. self.path("*.tex", "*.jpg")
  35. if self.prefix("nested", dst=""):
  36. self.path("deep")
  37. self.end_prefix()
  38. self.end_prefix("dir_1")
  39. class Demo_ArchManifest(llmanifest.LLManifest):
  40. pass
  41. class TestLLManifest(unittest.TestCase):
  42. mode='static'
  43. def setUp(self):
  44. self.m = llmanifest.LLManifest({'source':'src', 'dest':'dst', 'grid':'default', 'platform':'darwin', 'version':(1,2,3,4),
  45. 'artwork':'art', 'build':'build'})
  46. def testproperwindowspath(self):
  47. self.assertEqual(llmanifest.proper_windows_path("C:\Program Files", "cygwin"),"/cygdrive/c/Program Files")
  48. self.assertEqual(llmanifest.proper_windows_path("C:\Program Files", "windows"), "C:\Program Files")
  49. self.assertEqual(llmanifest.proper_windows_path("/cygdrive/c/Program Files/NSIS", "windows"), "C:\Program Files\NSIS")
  50. self.assertEqual(llmanifest.proper_windows_path("/cygdrive/c/Program Files/NSIS", "cygwin"), "/cygdrive/c/Program Files/NSIS")
  51. def testpathancestors(self):
  52. self.assertEqual(["dir"], [p for p in llmanifest.path_ancestors("dir")])
  53. self.assertEqual(["dir/sub", "dir"], [p for p in llmanifest.path_ancestors("dir/sub")])
  54. self.assertEqual(["dir/sub", "dir"], [p for p in llmanifest.path_ancestors("dir/sub/")])
  55. self.assertEqual(["dir/sub/two", "dir/sub", "dir"], [p for p in llmanifest.path_ancestors("dir/sub/two")])
  56. def testforplatform(self):
  57. self.assertEqual(llmanifest.LLManifest.for_platform('demo'), DemoManifest)
  58. def tmp_test():
  59. return llmanifest.LLManifest.for_platform('extant')
  60. self.assertRaises(KeyError, tmp_test)
  61. ExtantManifest = llmanifest.LLManifestRegistry('ExtantManifest', (llmanifest.LLManifest,), {})
  62. self.assertEqual(llmanifest.LLManifest.for_platform('extant'), ExtantManifest)
  63. self.assertEqual(llmanifest.LLManifest.for_platform('demo', 'Arch'), Demo_ArchManifest)
  64. def testprefix(self):
  65. self.assertEqual(self.m.get_src_prefix(), "src")
  66. self.assertEqual(self.m.get_dst_prefix(), "dst")
  67. self.m.prefix("level1")
  68. self.assertEqual(self.m.get_src_prefix(), "src/level1")
  69. self.assertEqual(self.m.get_dst_prefix(), "dst/level1")
  70. self.m.end_prefix()
  71. self.m.prefix(src="src", dst="dst")
  72. self.assertEqual(self.m.get_src_prefix(), "src/src")
  73. self.assertEqual(self.m.get_dst_prefix(), "dst/dst")
  74. self.m.end_prefix()
  75. def testendprefix(self):
  76. self.assertEqual(self.m.get_src_prefix(), "src")
  77. self.assertEqual(self.m.get_dst_prefix(), "dst")
  78. self.m.prefix("levela")
  79. self.m.end_prefix()
  80. self.assertEqual(self.m.get_src_prefix(), "src")
  81. self.assertEqual(self.m.get_dst_prefix(), "dst")
  82. self.m.prefix("level1")
  83. self.m.end_prefix("level1")
  84. self.assertEqual(self.m.get_src_prefix(), "src")
  85. self.assertEqual(self.m.get_dst_prefix(), "dst")
  86. self.m.prefix("level1")
  87. def tmp_test():
  88. self.m.end_prefix("mismatch")
  89. self.assertRaises(ValueError, tmp_test)
  90. def testruncommand(self):
  91. self.assertEqual("Hello\n", self.m.run_command("echo Hello"))
  92. def exit_1_test():
  93. self.m.run_command("exit 1")
  94. self.assertRaises(RuntimeError, exit_1_test)
  95. def not_found_test():
  96. self.m.run_command("test_command_that_should_not_be_found")
  97. self.assertRaises(RuntimeError, not_found_test)
  98. def testpathof(self):
  99. self.assertEqual(self.m.src_path_of("a"), "src/a")
  100. self.assertEqual(self.m.dst_path_of("a"), "dst/a")
  101. self.m.prefix("tmp")
  102. self.assertEqual(self.m.src_path_of("b/c"), "src/tmp/b/c")
  103. self.assertEqual(self.m.dst_path_of("b/c"), "dst/tmp/b/c")
  104. def testcmakedirs(self):
  105. self.m.cmakedirs("test_dir_DELETE/nested/dir")
  106. self.assert_(os.path.exists("test_dir_DELETE/nested/dir"))
  107. self.assert_(os.path.isdir("test_dir_DELETE"))
  108. self.assert_(os.path.isdir("test_dir_DELETE/nested"))
  109. self.assert_(os.path.isdir("test_dir_DELETE/nested/dir"))
  110. os.removedirs("test_dir_DELETE/nested/dir")
  111. if __name__ == '__main__':
  112. unittest.main()