-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
73 lines (56 loc) · 2.86 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
"""
tests.py: Unit tests for helpers used by run_python_tests.py.
"""
import functools
import os
import settings
import util
import unittest
class UtilTests(unittest.TestCase):
def setUp(self):
class MockView(object):
def file_name(self):
return os.path.join(
settings.PYTHON_TESTS_PACKAGE_DIR,
'test_files', 'test_app', 'tests.py')
self.mock_view = MockView()
self.orig_get_current_test_function = util.get_current_test_function
util.get_current_test_function = lambda view: 'test_fake'
self.test_files_dir = os.path.join(settings.PYTHON_TESTS_PACKAGE_DIR,
'test_files')
def tearDown(self):
util.get_current_test_function = self.orig_get_current_test_function
def test_find_file_finds_one_valid_dir_of_one_valid(self):
dir = util.find_dir_containing(['setup.py'],
os.path.join(self.test_files_dir, 'test_app'))
self.assertEqual(dir, self.test_files_dir)
def test_find_file_finds_one_valid_dir_of_two_valid(self):
dir = util.find_dir_containing(['setup.py', 'settings.py'],
os.path.join(self.test_files_dir, 'test_app'))
self.assertEqual(dir, self.test_files_dir)
def test_find_file_finds_one_valid_dir_of_one_valid_one_invalid(self):
dir = util.find_dir_containing(['setup.py', 'not_real.py'],
os.path.join(self.test_files_dir, 'test_app'))
self.assertEqual(dir, self.test_files_dir)
def test_find_file_returns_none_if_none_valid(self):
dir = util.find_dir_containing(['not_real.py', 'also_not_real.py'],
os.path.join(self.test_files_dir, 'test_app'))
self.assertEqual(dir, None)
def test_get_django_test_method(self):
test_name = util.get_test_name(self.mock_view, 'django', 'method')
self.assertEqual('test_app.FakeTestClass.test_fake', test_name)
def test_get_django_test_class(self):
test_name = util.get_test_name(self.mock_view, 'django', 'class')
self.assertEqual('test_app.FakeTestClass', test_name)
def test_get_django_test_suite(self):
test_name = util.get_test_name(self.mock_view, 'django', 'suite')
self.assertEqual('test_app', test_name)
def test_get_nose_test_method(self):
test_name = util.get_test_name(self.mock_view, 'nose', 'method')
self.assertEqual('test_app.tests:FakeTestClass.test_fake', test_name)
def test_get_nose_test_class(self):
test_name = util.get_test_name(self.mock_view, 'nose', 'class')
self.assertEqual('test_app.tests:FakeTestClass', test_name)
def test_get_nose_test_suite(self):
test_name = util.get_test_name(self.mock_view, 'nose', 'suite')
self.assertEqual('test_app.tests', test_name)