libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From je...@apache.org
Subject svn commit: r919879 - in /incubator/libcloud/trunk/test: file_fixture.py fixtures/ fixtures/meta/ fixtures/meta/helloworld.txt test_file_fixture.py
Date Sat, 06 Mar 2010 23:59:32 GMT
Author: jerry
Date: Sat Mar  6 23:59:32 2010
New Revision: 919879

URL: http://svn.apache.org/viewvc?rev=919879&view=rev
Log:
FileFixture helper class in test/

Added:
    incubator/libcloud/trunk/test/file_fixture.py
    incubator/libcloud/trunk/test/fixtures/
    incubator/libcloud/trunk/test/fixtures/meta/
    incubator/libcloud/trunk/test/fixtures/meta/helloworld.txt
    incubator/libcloud/trunk/test/test_file_fixture.py

Added: incubator/libcloud/trunk/test/file_fixture.py
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/test/file_fixture.py?rev=919879&view=auto
==============================================================================
--- incubator/libcloud/trunk/test/file_fixture.py (added)
+++ incubator/libcloud/trunk/test/file_fixture.py Sat Mar  6 23:59:32 2010
@@ -0,0 +1,31 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# libcloud.org licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Helper class for loading large fixture data
+
+import os
+
+FILE_FIXTURE_ROOT = 'fixtures'
+
+class FileFixture:
+    def __init__(self, root):
+        self.root = os.path.join(FILE_FIXTURE_ROOT, root)
+
+    def load(self, file):
+        path = os.path.join(self.root, file)
+        if os.path.exists(path):
+            return open(path, 'r').read()
+        else:
+            raise IOError

Added: incubator/libcloud/trunk/test/fixtures/meta/helloworld.txt
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/test/fixtures/meta/helloworld.txt?rev=919879&view=auto
==============================================================================
--- incubator/libcloud/trunk/test/fixtures/meta/helloworld.txt (added)
+++ incubator/libcloud/trunk/test/fixtures/meta/helloworld.txt Sat Mar  6 23:59:32 2010
@@ -0,0 +1 @@
+Hello, World!
\ No newline at end of file

Added: incubator/libcloud/trunk/test/test_file_fixture.py
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/test/test_file_fixture.py?rev=919879&view=auto
==============================================================================
--- incubator/libcloud/trunk/test/test_file_fixture.py (added)
+++ incubator/libcloud/trunk/test/test_file_fixture.py Sat Mar  6 23:59:32 2010
@@ -0,0 +1,32 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# libcloud.org licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+from file_fixture import FileFixture
+
+import sys
+import unittest
+
+class FileFixtureTests(unittest.TestCase):
+
+    def test_success(self):
+        f = FileFixture('meta')
+        self.assertEqual("Hello, World!", f.load('helloworld.txt'))
+
+    def test_failure(self):
+        f = FileFixture('meta')
+        self.assertRaises(IOError, f.load, 'nil')
+
+if __name__ == '__main__':
+    sys.exit(unittest.main())



Mime
View raw message