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.

test_import_graph.py 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. # Copyright (c) 2006-2008, 2010, 2013 LOGILAB S.A. (Paris, FRANCE) <contact@logilab.fr>
  2. # Copyright (c) 2012 FELD Boris <lothiraldan@gmail.com>
  3. # Copyright (c) 2014-2017 Claudiu Popa <pcmanticore@gmail.com>
  4. # Copyright (c) 2014 Google, Inc.
  5. # Copyright (c) 2015 Ionel Cristian Maries <contact@ionelmc.ro>
  6. # Copyright (c) 2016 Derek Gustafson <degustaf@gmail.com>
  7. # Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  8. # For details: https://github.com/PyCQA/pylint/blob/master/COPYING
  9. import os
  10. from os.path import exists
  11. import pytest
  12. from pylint.checkers import initialize, imports
  13. from pylint.lint import PyLinter
  14. import pylint.testutils as testutils
  15. @pytest.fixture
  16. def dest():
  17. dest = 'dependencies_graph.dot'
  18. yield dest
  19. os.remove(dest)
  20. def test_dependencies_graph(dest):
  21. imports._dependencies_graph(dest, {'labas': ['hoho', 'yep'],
  22. 'hoho': ['yep']})
  23. with open(dest) as stream:
  24. assert stream.read().strip() == '''
  25. digraph "dependencies_graph" {
  26. rankdir=LR
  27. charset="utf-8"
  28. URL="." node[shape="box"]
  29. "hoho" [];
  30. "yep" [];
  31. "labas" [];
  32. "yep" -> "hoho" [];
  33. "hoho" -> "labas" [];
  34. "yep" -> "labas" [];
  35. }
  36. '''.strip()
  37. @pytest.fixture
  38. def linter():
  39. l = PyLinter(reporter=testutils.TestReporter())
  40. initialize(l)
  41. return l
  42. @pytest.fixture
  43. def remove_files():
  44. yield
  45. for fname in ('import.dot', 'ext_import.dot', 'int_import.dot'):
  46. try:
  47. os.remove(fname)
  48. except:
  49. pass
  50. @pytest.mark.usefixture("remove_files")
  51. def test_checker_dep_graphs(linter):
  52. l = linter
  53. l.global_set_option('persistent', False)
  54. l.global_set_option('reports', True)
  55. l.global_set_option('enable', 'imports')
  56. l.global_set_option('import-graph', 'import.dot')
  57. l.global_set_option('ext-import-graph', 'ext_import.dot')
  58. l.global_set_option('int-import-graph', 'int_import.dot')
  59. l.global_set_option('int-import-graph', 'int_import.dot')
  60. # ignore this file causing spurious MemoryError w/ some python version (>=2.3?)
  61. l.global_set_option('ignore', ('func_unknown_encoding.py',))
  62. l.check('input')
  63. l.generate_reports()
  64. assert exists('import.dot')
  65. assert exists('ext_import.dot')
  66. assert exists('int_import.dot')