00001
00002 """
00003 @file test_llmanifest.py
00004 @author Ryan Williams
00005 @brief Test cases for LLManifest library.
00006
00007 $LicenseInfo:firstyear=2006&license=viewergpl$
00008
00009 Copyright (c) 2006-2008, Linden Research, Inc.
00010
00011 Second Life Viewer Source Code
00012 The source code in this file ("Source Code") is provided by Linden Lab
00013 to you under the terms of the GNU General Public License, version 2.0
00014 ("GPL"), unless you have obtained a separate licensing agreement
00015 ("Other License"), formally executed by you and Linden Lab. Terms of
00016 the GPL can be found in doc/GPL-license.txt in this distribution, or
00017 online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
00018
00019 There are special exceptions to the terms and conditions of the GPL as
00020 it is applied to this Source Code. View the full text of the exception
00021 in the file doc/FLOSS-exception.txt in this software distribution, or
00022 online at http://secondlifegrid.net/programs/open_source/licensing/flossexception
00023
00024 By copying, modifying or distributing this software, you acknowledge
00025 that you have read and understood your obligations described above,
00026 and agree to abide by those obligations.
00027
00028 ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
00029 WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
00030 COMPLETENESS OR PERFORMANCE.
00031 $/LicenseInfo$
00032 """
00033
00034 from indra.util import llmanifest
00035 import os.path
00036 import os
00037 import unittest
00038
00039 class DemoManifest(llmanifest.LLManifest):
00040 def construct(self):
00041 super(DemoManifest, self).construct()
00042 if self.prefix("dir_1"):
00043 self.path("test_a")
00044 self.path(src="test_b", dst="test_dst_b")
00045 self.path("*.test")
00046 self.path("*.tex", "*.jpg")
00047 if self.prefix("nested", dst=""):
00048 self.path("deep")
00049 self.end_prefix()
00050 self.end_prefix("dir_1")
00051
00052
00053 class Demo_ArchManifest(llmanifest.LLManifest):
00054 pass
00055
00056 class TestLLManifest(unittest.TestCase):
00057 mode='static'
00058 def setUp(self):
00059 self.m = llmanifest.LLManifest("src", "dst", {'grid':'default', 'platform':'darwin', 'version':(1,2,3,4)})
00060
00061 def testproperwindowspath(self):
00062 self.assertEqual(llmanifest.proper_windows_path("C:\Program Files", "cygwin"),"/cygdrive/c/Program Files")
00063 self.assertEqual(llmanifest.proper_windows_path("C:\Program Files", "windows"), "C:\Program Files")
00064 self.assertEqual(llmanifest.proper_windows_path("/cygdrive/c/Program Files/NSIS", "windows"), "C:\Program Files\NSIS")
00065 self.assertEqual(llmanifest.proper_windows_path("/cygdrive/c/Program Files/NSIS", "cygwin"), "/cygdrive/c/Program Files/NSIS")
00066
00067 def testpathancestors(self):
00068 self.assertEqual(["dir"], [p for p in llmanifest.path_ancestors("dir")])
00069 self.assertEqual(["dir/sub", "dir"], [p for p in llmanifest.path_ancestors("dir/sub")])
00070 self.assertEqual(["dir/sub", "dir"], [p for p in llmanifest.path_ancestors("dir/sub/")])
00071 self.assertEqual(["dir/sub/two", "dir/sub", "dir"], [p for p in llmanifest.path_ancestors("dir/sub/two")])
00072
00073
00074 def testforplatform(self):
00075 self.assertEqual(llmanifest.LLManifest.for_platform('demo'), DemoManifest)
00076 def tmp_test():
00077 return llmanifest.LLManifest.for_platform('extant')
00078 self.assertRaises(KeyError, tmp_test)
00079 ExtantManifest = llmanifest.LLManifestRegistry('ExtantManifest', (llmanifest.LLManifest,), {})
00080 self.assertEqual(llmanifest.LLManifest.for_platform('extant'), ExtantManifest)
00081 self.assertEqual(llmanifest.LLManifest.for_platform('demo', 'Arch'), Demo_ArchManifest)
00082
00083
00084 def testprefix(self):
00085 self.assertEqual(self.m.get_src_prefix(), "src")
00086 self.assertEqual(self.m.get_dst_prefix(), "dst")
00087 self.m.prefix("level1")
00088 self.assertEqual(self.m.get_src_prefix(), "src/level1")
00089 self.assertEqual(self.m.get_dst_prefix(), "dst/level1")
00090 self.m.end_prefix()
00091 self.m.prefix(src="src", dst="dst")
00092 self.assertEqual(self.m.get_src_prefix(), "src/src")
00093 self.assertEqual(self.m.get_dst_prefix(), "dst/dst")
00094 self.m.end_prefix()
00095
00096 def testendprefix(self):
00097 self.assertEqual(self.m.get_src_prefix(), "src")
00098 self.assertEqual(self.m.get_dst_prefix(), "dst")
00099 self.m.prefix("levela")
00100 self.m.end_prefix()
00101 self.assertEqual(self.m.get_src_prefix(), "src")
00102 self.assertEqual(self.m.get_dst_prefix(), "dst")
00103 self.m.prefix("level1")
00104 self.m.end_prefix("level1")
00105 self.assertEqual(self.m.get_src_prefix(), "src")
00106 self.assertEqual(self.m.get_dst_prefix(), "dst")
00107 self.m.prefix("level1")
00108 def tmp_test():
00109 self.m.end_prefix("mismatch")
00110 self.assertRaises(ValueError, tmp_test)
00111
00112 def testruncommand(self):
00113 self.assertEqual("Hello\n", self.m.run_command("echo Hello"))
00114 def exit_1_test():
00115 self.m.run_command("exit 1")
00116 self.assertRaises(RuntimeError, exit_1_test)
00117 def not_found_test():
00118 self.m.run_command("test_command_that_should_not_be_found")
00119 self.assertRaises(RuntimeError, not_found_test)
00120
00121
00122 def testpathof(self):
00123 self.assertEqual(self.m.src_path_of("a"), "src/a")
00124 self.assertEqual(self.m.dst_path_of("a"), "dst/a")
00125 self.m.prefix("tmp")
00126 self.assertEqual(self.m.src_path_of("b/c"), "src/tmp/b/c")
00127 self.assertEqual(self.m.dst_path_of("b/c"), "dst/tmp/b/c")
00128
00129 def testcmakedirs(self):
00130 self.m.cmakedirs("test_dir_DELETE/nested/dir")
00131 self.assert_(os.path.exists("test_dir_DELETE/nested/dir"))
00132 self.assert_(os.path.isdir("test_dir_DELETE"))
00133 self.assert_(os.path.isdir("test_dir_DELETE/nested"))
00134 self.assert_(os.path.isdir("test_dir_DELETE/nested/dir"))
00135 os.removedirs("test_dir_DELETE/nested/dir")
00136
00137 if __name__ == '__main__':
00138 unittest.main()