Development of an internal social media platform with personalised dashboards for students
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

resources.py 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # Copyright (c) 2014 Google, Inc.
  2. # Copyright (c) 2015-2016 Claudiu Popa <pcmanticore@gmail.com>
  3. # Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
  4. # For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
  5. import os
  6. import sys
  7. import pkg_resources
  8. from astroid import builder
  9. from astroid import MANAGER
  10. from astroid.bases import BUILTINS
  11. from astroid import tests
  12. DATA_DIR = os.path.join('testdata', 'python{}'.format(sys.version_info[0]))
  13. RESOURCE_PATH = os.path.join(tests.__path__[0], DATA_DIR, 'data')
  14. def find(name):
  15. return pkg_resources.resource_filename(
  16. 'astroid.tests', os.path.normpath(os.path.join(DATA_DIR, name)))
  17. def build_file(path, modname=None):
  18. return builder.AstroidBuilder().file_build(find(path), modname)
  19. class SysPathSetup(object):
  20. def setUp(self):
  21. sys.path.insert(0, find(''))
  22. def tearDown(self):
  23. del sys.path[0]
  24. datadir = find('')
  25. for key in list(sys.path_importer_cache):
  26. if key.startswith(datadir):
  27. del sys.path_importer_cache[key]
  28. class AstroidCacheSetupMixin(object):
  29. """Mixin for handling the astroid cache problems.
  30. When clearing the astroid cache, some tests fails due to
  31. cache inconsistencies, where some objects had a different
  32. builtins object referenced.
  33. This saves the builtins module and makes sure to add it
  34. back to the astroid_cache after the tests finishes.
  35. The builtins module is special, since some of the
  36. transforms for a couple of its objects (str, bytes etc)
  37. are executed only once, so astroid_bootstrapping will be
  38. useless for retrieving the original builtins module.
  39. """
  40. @classmethod
  41. def setUpClass(cls):
  42. cls._builtins = MANAGER.astroid_cache.get(BUILTINS)
  43. @classmethod
  44. def tearDownClass(cls):
  45. if cls._builtins:
  46. MANAGER.astroid_cache[BUILTINS] = cls._builtins