Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Side by Side Diff: appengine/monorail/testing/test/fake_test.py

Issue 1868553004: Open Source Monorail (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Rebase Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 # Copyright 2016 The Chromium Authors. All rights reserved.
2 # Use of this source code is govered by a BSD-style
3 # license that can be found in the LICENSE file or at
4 # https://developers.google.com/open-source/licenses/bsd
5
6 """Tests for the fake module."""
7
8 import inspect
9 import unittest
10
11 from services import cachemanager_svc
12 from services import config_svc
13 from services import issue_svc
14 from services import project_svc
15 from services import star_svc
16 from services import user_svc
17 from services import usergroup_svc
18 from testing import fake
19
20 fake_class_map = {
21 fake.AbstractStarService: star_svc.AbstractStarService,
22 fake.CacheManager: cachemanager_svc.CacheManager,
23 fake.ProjectService: project_svc.ProjectService,
24 fake.ConfigService: config_svc.ConfigService,
25 fake.IssueService: issue_svc.IssueService,
26 fake.UserGroupService: usergroup_svc.UserGroupService,
27 fake.UserService: user_svc.UserService,
28 }
29
30
31 class FakeMetaTest(unittest.TestCase):
32
33 def testFunctionsHaveSameSignatures(self):
34 """Verify that the fake class methods match the real ones."""
35 for fake_cls, real_cls in fake_class_map.iteritems():
36 fake_attrs = set(dir(fake_cls))
37 real_attrs = set(dir(real_cls))
38 both_attrs = fake_attrs.intersection(real_attrs)
39 to_test = [x for x in both_attrs if '__' not in x]
40 for name in to_test:
41 real_attr = getattr(real_cls, name)
42 if inspect.ismethod(real_attr):
43 real_spec = inspect.getargspec(real_attr)
44 fake_spec = inspect.getargspec(getattr(fake_cls, name))
45 # check same number of args and kwargs
46 real_kw_len = real_spec[3] and len(real_spec[3]) or 0
47 fake_kw_len = fake_spec[3] and len(fake_spec[3]) or 0
48
49 self.assertEquals(
50 len(real_spec[0]) - real_kw_len,
51 len(fake_spec[0]) - fake_kw_len,
52 'Unequal number of args on %s.%s' % (fake_cls.__name__, name))
53 self.assertEquals(
54 real_kw_len, fake_kw_len,
55 'Unequal number of kwargs on %s.%s' % (fake_cls.__name__, name))
56 if real_kw_len:
57 self.assertEquals(
58 real_spec[0][-real_kw_len:],
59 fake_spec[0][-fake_kw_len:],
60 'Mismatched kwargs on %s.%s' % (fake_cls.__name__, name))
61 self.assertEquals(
62 real_spec[3], fake_spec[3],
63 'Mismatched kwarg defaults on %s.%s' % (fake_cls.__name__, name))
64
65
66 if __name__ == '__main__':
67 unittest.main()
OLDNEW
« no previous file with comments | « appengine/monorail/testing/test/__init__.py ('k') | appengine/monorail/testing/test/testing_helpers_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698