fixtures.py 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. # vim: set fileencoding=utf-8 :
  2. #
  3. # (C) 2017 Guido Guenther <agx@sigxcpu.org>
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 2 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, please see
  16. # <http://www.gnu.org/licenses/>
  17. import os
  18. from functools import wraps
  19. from tests.component import (ComponentTestBase,
  20. ComponentTestGitRepository)
  21. from tests.component.deb import DEB_TEST_DATA_DIR
  22. from nose.tools import eq_
  23. from gbp.deb.dscfile import DscFile
  24. from gbp.scripts.import_dsc import main as import_dsc
  25. DEFAULT_NATIVE = os.path.join(DEB_TEST_DATA_DIR,
  26. 'dsc-native',
  27. 'git-buildpackage_%s.dsc' % '0.4.14')
  28. DEFAULT_QUILT30 = os.path.join(DEB_TEST_DATA_DIR,
  29. 'dsc-3.0',
  30. 'hello-debhelper_%s.dsc' % '2.8-1')
  31. class RepoFixtures(object):
  32. @classmethod
  33. def native(cls, dsc=DEFAULT_NATIVE, opts=None):
  34. """Docorator to be used as Debian native test fixture"""
  35. def wrapper(fn):
  36. @wraps(fn)
  37. def _native_repo(*args):
  38. repo = cls.import_native(dsc, opts)
  39. return fn(*args, repo=repo)
  40. return _native_repo
  41. return wrapper
  42. @classmethod
  43. def quilt30(cls, dsc=DEFAULT_QUILT30, opts=None):
  44. """Decorator to be used as 3.0 (quilt) test fixture"""
  45. def wrapper(fn):
  46. @wraps(fn)
  47. def _quilt30_repo(*args):
  48. repo = cls.import_quilt30(dsc, opts)
  49. return fn(*args, repo=repo)
  50. return _quilt30_repo
  51. return wrapper
  52. @classmethod
  53. def _import_one(cls, dsc, opts):
  54. opts = opts or []
  55. assert import_dsc(['arg0'] + opts + [dsc]) == 0
  56. parsed = DscFile(dsc)
  57. return ComponentTestGitRepository(parsed.pkg)
  58. @classmethod
  59. def import_native(cls, dsc=DEFAULT_NATIVE, opts=None):
  60. """Import a Debian native package, verify and change into repo"""
  61. repo = cls._import_one(dsc, opts)
  62. ComponentTestBase._check_repo_state(repo, 'master', ['master'])
  63. eq_(len(repo.get_commits()), 1)
  64. os.chdir(repo.path)
  65. return repo
  66. @classmethod
  67. def import_quilt30(cls, dsc=DEFAULT_QUILT30, opts=None):
  68. """Import a 3.0 (quilt) package, verify and change into repo"""
  69. repo = cls._import_one(dsc, opts)
  70. expected_branches = ['master', 'upstream']
  71. if opts and '--pristine-tar' in opts:
  72. expected_branches.append('pristine-tar')
  73. ComponentTestBase._check_repo_state(repo, 'master', expected_branches)
  74. eq_(len(repo.get_commits()), 2)
  75. os.chdir(repo.path)
  76. return repo