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

Subscribers

People subscribed via source and target branches