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