Merge lp:~gesha/linaro-license-protection/textile-view into lp:~linaro-infrastructure/linaro-license-protection/textile-view

Proposed by Georgy Redkozubov
Status: Merged
Approved by: Stevan Radaković
Approved revision: 139
Merged at revision: 140
Proposed branch: lp:~gesha/linaro-license-protection/textile-view
Merge into: lp:~linaro-infrastructure/linaro-license-protection/textile-view
Diff against target: 151 lines (+121/-1)
2 files modified
license_protected_downloads/tests/__init__.py (+3/-0)
license_protected_downloads/tests/test_render_text_files.py (+118/-1)
To merge this branch: bzr merge lp:~gesha/linaro-license-protection/textile-view
Reviewer Review Type Date Requested Status
Stevan Radaković Approve
Review via email: mp+129808@code.launchpad.net

Description of the change

This branch adds tests for RenderTextFiles class.

To post a comment you must log in.
Revision history for this message
Stevan Radaković (stevanr) wrote :

Looks good to go into our branch.
Thanks gesha.
Approve +1.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'license_protected_downloads/tests/__init__.py'
2--- license_protected_downloads/tests/__init__.py 2012-08-22 21:49:30 +0000
3+++ license_protected_downloads/tests/__init__.py 2012-10-16 07:13:21 +0000
4@@ -6,6 +6,8 @@
5 from license_protected_downloads.tests.test_openid_auth import TestOpenIDAuth
6 from license_protected_downloads.tests.test_custom_commands \
7 import SetsuperuserCommandTest
8+from license_protected_downloads.tests.test_render_text_files \
9+ import RenderTextFilesTests
10
11 #starts the test suite
12 __test__ = {
13@@ -16,4 +18,5 @@
14 'TestPyflakes': TestPyflakes,
15 'TestOpenIDAuth': TestOpenIDAuth,
16 'SetsuperuserCommandTest': SetsuperuserCommandTest,
17+ 'RenderTextFilesTests': RenderTextFilesTests,
18 }
19
20=== modified file 'license_protected_downloads/tests/test_render_text_files.py'
21--- license_protected_downloads/tests/test_render_text_files.py 2012-10-11 09:48:13 +0000
22+++ license_protected_downloads/tests/test_render_text_files.py 2012-10-16 07:13:21 +0000
23@@ -1,6 +1,15 @@
24 import os
25 import unittest
26-#from license_protected_downloads.render_text_files import RenderTextFiles
27+import tempfile
28+import shutil
29+import re
30+from license_protected_downloads.render_text_files import RenderTextFiles
31+from license_protected_downloads.render_text_files import NoFilesException
32+from license_protected_downloads.render_text_files import \
33+ MultipleFilesException
34+from license_protected_downloads.render_text_files import ANDROID_FILES
35+from license_protected_downloads.render_text_files import UBUNTU_FILES
36+
37
38 THIS_DIRECTORY = os.path.dirname(os.path.abspath(__file__))
39
40@@ -8,3 +17,111 @@
41 class RenderTextFilesTests(unittest.TestCase):
42 def setUp(self):
43 pass
44+
45+ def test_flatten_list(self):
46+ l = ['1', ['2', '3']]
47+ self.assertEqual(['1', '2', '3'], RenderTextFiles.flatten(l))
48+
49+ def test_flatten_tuple(self):
50+ l = ('1', ('2', '3'))
51+ self.assertEqual(('1', '2', '3'), RenderTextFiles.flatten(l))
52+
53+ def test_findall(self):
54+ l = ['1test', 'test2', '3', 'test', '1']
55+ self.assertEqual([0, 1, 3],
56+ RenderTextFiles.findall(l, lambda x: re.search(r'test', x)))
57+
58+ def test_findall_empty(self):
59+ l = []
60+ self.assertEqual([],
61+ RenderTextFiles.findall(l, lambda x: re.search(r'1', x)))
62+
63+ def make_temp_dir(self, empty=True, file_list=None, dir=None):
64+ path = tempfile.mkdtemp(dir=dir)
65+ if not empty:
66+ if file_list:
67+ for file in file_list:
68+ handle, fname = tempfile.mkstemp(dir=path)
69+ shutil.move(fname, os.path.join(path, file))
70+ return path
71+
72+ def test_find_relevant_files_no_files(self):
73+ path = self.make_temp_dir()
74+ with self.assertRaises(NoFilesException):
75+ RenderTextFiles.find_relevant_files(path)
76+
77+ def test_find_relevant_files_multiple_files(self):
78+ path = tempfile.mkdtemp()
79+ handle, fname = tempfile.mkstemp(dir=path)
80+ shutil.move(fname, os.path.join(path, 'README'))
81+ path1 = tempfile.mkdtemp(dir=path)
82+ handle, fname = tempfile.mkstemp(dir=path1)
83+ shutil.move(fname, os.path.join(path1, 'README'))
84+ with self.assertRaises(MultipleFilesException):
85+ RenderTextFiles.find_relevant_files(path)
86+
87+ def test_find_relevant_files_android(self):
88+ path = self.make_temp_dir(empty=False, file_list=ANDROID_FILES)
89+ full_android_files = []
90+ for file in ANDROID_FILES:
91+ full_android_files.append(os.path.join(path, file))
92+ self.assertEqual(full_android_files,
93+ RenderTextFiles.find_relevant_files(path))
94+
95+ def test_find_relevant_files_android_subdir(self):
96+ path = self.make_temp_dir()
97+ full_path = self.make_temp_dir(empty=False, file_list=ANDROID_FILES,
98+ dir=path)
99+ full_android_files = []
100+ for file in ANDROID_FILES:
101+ full_android_files.append(os.path.join(full_path, file))
102+ self.assertEqual(full_android_files,
103+ RenderTextFiles.find_relevant_files(path))
104+ self.assertEqual(full_android_files,
105+ RenderTextFiles.find_relevant_files(full_path))
106+
107+ def test_find_relevant_files_android_several_subdirs(self):
108+ path = self.make_temp_dir()
109+ full_path1 = self.make_temp_dir(empty=False, file_list=ANDROID_FILES,
110+ dir=path)
111+ full_path2 = self.make_temp_dir(empty=False, file_list=ANDROID_FILES,
112+ dir=path)
113+ full_android_files1 = []
114+ full_android_files2 = []
115+ for file in ANDROID_FILES:
116+ full_android_files1.append(os.path.join(full_path1, file))
117+ full_android_files2.append(os.path.join(full_path2, file))
118+ with self.assertRaises(MultipleFilesException):
119+ RenderTextFiles.find_relevant_files(path)
120+ self.assertEqual(full_android_files1,
121+ RenderTextFiles.find_relevant_files(full_path1))
122+ self.assertEqual(full_android_files2,
123+ RenderTextFiles.find_relevant_files(full_path2))
124+
125+ def test_find_relevant_files_android_and_ubuntu_samedir(self):
126+ flist = ANDROID_FILES + UBUNTU_FILES
127+ path = self.make_temp_dir(empty=False, file_list=flist)
128+ full_files = []
129+ for file in flist:
130+ full_files.append(os.path.join(path, file))
131+ self.assertListEqual(sorted(full_files),
132+ sorted(RenderTextFiles.find_relevant_files(path)))
133+
134+ def test_find_relevant_files_android_and_ubuntu_different_subdirs(self):
135+ path = self.make_temp_dir()
136+ android_path = self.make_temp_dir(empty=False, file_list=ANDROID_FILES,
137+ dir=path)
138+ ubuntu_path = self.make_temp_dir(empty=False, file_list=UBUNTU_FILES,
139+ dir=path)
140+ full_android_files = []
141+ full_ubuntu_files = []
142+ for file in ANDROID_FILES:
143+ full_android_files.append(os.path.join(android_path, file))
144+ for file in UBUNTU_FILES:
145+ full_ubuntu_files.append(os.path.join(ubuntu_path, file))
146+ self.assertEqual(sorted(full_android_files + full_ubuntu_files),
147+ sorted(RenderTextFiles.find_relevant_files(path)))
148+ self.assertEqual(sorted(full_android_files),
149+ sorted(RenderTextFiles.find_relevant_files(android_path)))
150+ self.assertEqual(sorted(full_ubuntu_files),
151+ sorted(RenderTextFiles.find_relevant_files(ubuntu_path)))

Subscribers

People subscribed via source and target branches