##// END OF EJS Templates
dependencies: bumped test libraries.
marcink -
r3951:041016db default
parent child
Show More
Add another comment
@@ -0,0 +1,47
1 import collections
2 # -*- coding: utf-8 -*-
3
4 # Copyright (C) 2010-2019 RhodeCode GmbH
5 #
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU Affero General Public License, version 3
8 # (only), as published by the Free Software Foundation.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU Affero General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #
18 # This program is dual-licensed. If you wish to learn more about the
19 # RhodeCode Enterprise Edition, including its added features, Support services,
20 # and proprietary license terms, please see https://rhodecode.com/licenses/
21
22 import pytest
23
24 from rhodecode.lib import audit_logger
25
26
27 @pytest.mark.parametrize('store_type', [
28 'store_web',
29 'store_api'
30 ])
31 @pytest.mark.parametrize('action, kwargs', [
32 ('repo.edit', {
33 'user': audit_logger.UserWrap(username='test-audit-log', ip_addr='8.8.8.8'),
34 'action_data': {'data': {'hello': 'world'}}
35 }),
36 ('repo.edit', {
37 'user': audit_logger.UserWrap(username=u'marcinkużmiń', ip_addr='8.8.8.8'),
38 'action_data': {'data': {'hello': u'ąężą∑ęī¨¨ķ©'}}
39 }),
40 ('repo.edit', {
41 'user': audit_logger.UserWrap(username='marcinkużmiń', ip_addr='8.8.8.8'),
42 'action_data': {'data': {'hello': 'ąężą∑ęī¨¨ķ©'}}
43 }),
44 ])
45 def test_store_audit_log(app, store_type, action, kwargs):
46 store_action = getattr(audit_logger, store_type)
47 store_action(action, **kwargs)
@@ -311,11 +311,11
311 };
311 };
312 };
312 };
313 "coverage" = super.buildPythonPackage {
313 "coverage" = super.buildPythonPackage {
314 name = "coverage-4.5.3";
314 name = "coverage-4.5.4";
315 doCheck = false;
315 doCheck = false;
316 src = fetchurl {
316 src = fetchurl {
317 url = "https://files.pythonhosted.org/packages/82/70/2280b5b29a0352519bb95ab0ef1ea942d40466ca71c53a2085bdeff7b0eb/coverage-4.5.3.tar.gz";
317 url = "https://files.pythonhosted.org/packages/85/d5/818d0e603685c4a613d56f065a721013e942088047ff1027a632948bdae6/coverage-4.5.4.tar.gz";
318 sha256 = "02f6m073qdispn96rc616hg0rnmw1pgqzw3bgxwiwza4zf9hirlx";
318 sha256 = "0p0j4di6h8k6ica7jwwj09azdcg4ycxq60i9qsskmsg94cd9yzg0";
319 };
319 };
320 meta = {
320 meta = {
321 license = [ pkgs.lib.licenses.asl20 ];
321 license = [ pkgs.lib.licenses.asl20 ];
@@ -961,14 +961,18
961 };
961 };
962 };
962 };
963 "mock" = super.buildPythonPackage {
963 "mock" = super.buildPythonPackage {
964 name = "mock-1.0.1";
964 name = "mock-3.0.5";
965 doCheck = false;
965 doCheck = false;
966 propagatedBuildInputs = [
967 self."six"
968 self."funcsigs"
969 ];
966 src = fetchurl {
970 src = fetchurl {
967 url = "https://files.pythonhosted.org/packages/a2/52/7edcd94f0afb721a2d559a5b9aae8af4f8f2c79bc63fdbe8a8a6c9b23bbe/mock-1.0.1.tar.gz";
971 url = "https://files.pythonhosted.org/packages/2e/ab/4fe657d78b270aa6a32f027849513b829b41b0f28d9d8d7f8c3d29ea559a/mock-3.0.5.tar.gz";
968 sha256 = "0kzlsbki6q0awf89rc287f3aj8x431lrajf160a70z0ikhnxsfdq";
972 sha256 = "1hrp6j0yrx2xzylfv02qa8kph661m6yq4p0mc8fnimch9j4psrc3";
969 };
973 };
970 meta = {
974 meta = {
971 license = [ pkgs.lib.licenses.bsdOriginal ];
975 license = [ pkgs.lib.licenses.bsdOriginal { fullName = "OSI Approved :: BSD License"; } ];
972 };
976 };
973 };
977 };
974 "more-itertools" = super.buildPythonPackage {
978 "more-itertools" = super.buildPythonPackage {
@@ -1253,11 +1257,11
1253 };
1257 };
1254 };
1258 };
1255 "py" = super.buildPythonPackage {
1259 "py" = super.buildPythonPackage {
1256 name = "py-1.6.0";
1260 name = "py-1.8.0";
1257 doCheck = false;
1261 doCheck = false;
1258 src = fetchurl {
1262 src = fetchurl {
1259 url = "https://files.pythonhosted.org/packages/4f/38/5f427d1eedae73063ce4da680d2bae72014995f9fdeaa57809df61c968cd/py-1.6.0.tar.gz";
1263 url = "https://files.pythonhosted.org/packages/f1/5a/87ca5909f400a2de1561f1648883af74345fe96349f34f737cdfc94eba8c/py-1.8.0.tar.gz";
1260 sha256 = "1wcs3zv9wl5m5x7p16avqj2gsrviyb23yvc3pr330isqs0sh98q6";
1264 sha256 = "0lsy1gajva083pzc7csj1cvbmminb7b4l6a0prdzyb3fd829nqyw";
1261 };
1265 };
1262 meta = {
1266 meta = {
1263 license = [ pkgs.lib.licenses.mit ];
1267 license = [ pkgs.lib.licenses.mit ];
@@ -1492,44 +1496,46
1492 };
1496 };
1493 };
1497 };
1494 "pytest" = super.buildPythonPackage {
1498 "pytest" = super.buildPythonPackage {
1495 name = "pytest-3.8.2";
1499 name = "pytest-4.6.5";
1496 doCheck = false;
1500 doCheck = false;
1497 propagatedBuildInputs = [
1501 propagatedBuildInputs = [
1498 self."py"
1502 self."py"
1499 self."six"
1503 self."six"
1500 self."setuptools"
1504 self."packaging"
1501 self."attrs"
1505 self."attrs"
1502 self."more-itertools"
1503 self."atomicwrites"
1506 self."atomicwrites"
1504 self."pluggy"
1507 self."pluggy"
1508 self."importlib-metadata"
1509 self."wcwidth"
1505 self."funcsigs"
1510 self."funcsigs"
1506 self."pathlib2"
1511 self."pathlib2"
1512 self."more-itertools"
1507 ];
1513 ];
1508 src = fetchurl {
1514 src = fetchurl {
1509 url = "https://files.pythonhosted.org/packages/5f/d2/7f77f406ac505abda02ab4afb50d06ebf304f6ea42fca34f8f37529106b2/pytest-3.8.2.tar.gz";
1515 url = "https://files.pythonhosted.org/packages/2a/c6/1d1f32f6a5009900521b12e6560fb6b7245b0d4bc3fb771acd63d10e30e1/pytest-4.6.5.tar.gz";
1510 sha256 = "18nrwzn61kph2y6gxwfz9ms68rfvr9d4vcffsxng9p7jk9z18clk";
1516 sha256 = "0iykwwfp4h181nd7rsihh2120b0rkawlw7rvbl19sgfspncr3hwg";
1511 };
1517 };
1512 meta = {
1518 meta = {
1513 license = [ pkgs.lib.licenses.mit ];
1519 license = [ pkgs.lib.licenses.mit ];
1514 };
1520 };
1515 };
1521 };
1516 "pytest-cov" = super.buildPythonPackage {
1522 "pytest-cov" = super.buildPythonPackage {
1517 name = "pytest-cov-2.6.0";
1523 name = "pytest-cov-2.7.1";
1518 doCheck = false;
1524 doCheck = false;
1519 propagatedBuildInputs = [
1525 propagatedBuildInputs = [
1520 self."pytest"
1526 self."pytest"
1521 self."coverage"
1527 self."coverage"
1522 ];
1528 ];
1523 src = fetchurl {
1529 src = fetchurl {
1524 url = "https://files.pythonhosted.org/packages/d9/e2/58f90a316fbd94dd50bf5c826a23f3f5d079fb3cc448c1e9f0e3c33a3d2a/pytest-cov-2.6.0.tar.gz";
1530 url = "https://files.pythonhosted.org/packages/bb/0f/3db7ff86801883b21d5353b258c994b1b8e2abbc804e2273b8d0fd19004b/pytest-cov-2.7.1.tar.gz";
1525 sha256 = "0qnpp9y3ygx4jk4pf5ad71fh2skbvnr6gl54m7rg5qysnx4g0q73";
1531 sha256 = "0filvmmyqm715azsl09ql8hy2x7h286n6d8z5x42a1wpvvys83p0";
1526 };
1532 };
1527 meta = {
1533 meta = {
1528 license = [ pkgs.lib.licenses.bsdOriginal pkgs.lib.licenses.mit ];
1534 license = [ pkgs.lib.licenses.bsdOriginal pkgs.lib.licenses.mit ];
1529 };
1535 };
1530 };
1536 };
1531 "pytest-profiling" = super.buildPythonPackage {
1537 "pytest-profiling" = super.buildPythonPackage {
1532 name = "pytest-profiling-1.3.0";
1538 name = "pytest-profiling-1.7.0";
1533 doCheck = false;
1539 doCheck = false;
1534 propagatedBuildInputs = [
1540 propagatedBuildInputs = [
1535 self."six"
1541 self."six"
@@ -1537,48 +1543,49
1537 self."gprof2dot"
1543 self."gprof2dot"
1538 ];
1544 ];
1539 src = fetchurl {
1545 src = fetchurl {
1540 url = "https://files.pythonhosted.org/packages/f5/34/4626126e041a51ef50a80d0619519b18d20aef249aac25b0d0fdd47e57ee/pytest-profiling-1.3.0.tar.gz";
1546 url = "https://files.pythonhosted.org/packages/39/70/22a4b33739f07f1732a63e33bbfbf68e0fa58cfba9d200e76d01921eddbf/pytest-profiling-1.7.0.tar.gz";
1541 sha256 = "08r5afx5z22yvpmsnl91l4amsy1yxn8qsmm61mhp06mz8zjs51kb";
1547 sha256 = "0abz9gi26jpcfdzgsvwad91555lpgdc8kbymicmms8k2fqa8z4wk";
1542 };
1548 };
1543 meta = {
1549 meta = {
1544 license = [ pkgs.lib.licenses.mit ];
1550 license = [ pkgs.lib.licenses.mit ];
1545 };
1551 };
1546 };
1552 };
1547 "pytest-runner" = super.buildPythonPackage {
1553 "pytest-runner" = super.buildPythonPackage {
1548 name = "pytest-runner-4.2";
1554 name = "pytest-runner-5.1";
1549 doCheck = false;
1555 doCheck = false;
1550 src = fetchurl {
1556 src = fetchurl {
1551 url = "https://files.pythonhosted.org/packages/9e/b7/fe6e8f87f9a756fd06722216f1b6698ccba4d269eac6329d9f0c441d0f93/pytest-runner-4.2.tar.gz";
1557 url = "https://files.pythonhosted.org/packages/d9/6d/4b41a74b31720e25abd4799be72d54811da4b4d0233e38b75864dcc1f7ad/pytest-runner-5.1.tar.gz";
1552 sha256 = "1gkpyphawxz38ni1gdq1fmwyqcg02m7ypzqvv46z06crwdxi2gyj";
1558 sha256 = "0ykfcnpp8c22winj63qzc07l5axwlc9ikl8vn05sc32gv3417815";
1553 };
1559 };
1554 meta = {
1560 meta = {
1555 license = [ pkgs.lib.licenses.mit ];
1561 license = [ pkgs.lib.licenses.mit ];
1556 };
1562 };
1557 };
1563 };
1558 "pytest-sugar" = super.buildPythonPackage {
1564 "pytest-sugar" = super.buildPythonPackage {
1559 name = "pytest-sugar-0.9.1";
1565 name = "pytest-sugar-0.9.2";
1560 doCheck = false;
1566 doCheck = false;
1561 propagatedBuildInputs = [
1567 propagatedBuildInputs = [
1562 self."pytest"
1568 self."pytest"
1563 self."termcolor"
1569 self."termcolor"
1570 self."packaging"
1564 ];
1571 ];
1565 src = fetchurl {
1572 src = fetchurl {
1566 url = "https://files.pythonhosted.org/packages/3e/6a/a3f909083079d03bde11d06ab23088886bbe25f2c97fbe4bb865e2bf05bc/pytest-sugar-0.9.1.tar.gz";
1573 url = "https://files.pythonhosted.org/packages/55/59/f02f78d1c80f7e03e23177f60624c8106d4f23d124c921df103f65692464/pytest-sugar-0.9.2.tar.gz";
1567 sha256 = "0b4av40dv30727m54v211r0nzwjp2ajkjgxix6j484qjmwpw935b";
1574 sha256 = "1asq7yc4g8bx2sn7yy974mhc9ywvaihasjab4inkirdwn9s7mn7w";
1568 };
1575 };
1569 meta = {
1576 meta = {
1570 license = [ pkgs.lib.licenses.bsdOriginal ];
1577 license = [ pkgs.lib.licenses.bsdOriginal ];
1571 };
1578 };
1572 };
1579 };
1573 "pytest-timeout" = super.buildPythonPackage {
1580 "pytest-timeout" = super.buildPythonPackage {
1574 name = "pytest-timeout-1.3.2";
1581 name = "pytest-timeout-1.3.3";
1575 doCheck = false;
1582 doCheck = false;
1576 propagatedBuildInputs = [
1583 propagatedBuildInputs = [
1577 self."pytest"
1584 self."pytest"
1578 ];
1585 ];
1579 src = fetchurl {
1586 src = fetchurl {
1580 url = "https://files.pythonhosted.org/packages/8c/3e/1b6a319d12ae7baa3acb7c18ff2c8630a09471a0319d43535c683b4d03eb/pytest-timeout-1.3.2.tar.gz";
1587 url = "https://files.pythonhosted.org/packages/13/48/7a166eaa29c1dca6cc253e3ba5773ff2e4aa4f567c1ea3905808e95ac5c1/pytest-timeout-1.3.3.tar.gz";
1581 sha256 = "09wnmzvnls2mnsdz7x3c3sk2zdp6jl4dryvyj5i8hqz16q2zq5qi";
1588 sha256 = "1cczcjhw4xx5sjkhxlhc5c1bkr7x6fcyx12wrnvwfckshdvblc2a";
1582 };
1589 };
1583 meta = {
1590 meta = {
1584 license = [ pkgs.lib.licenses.mit { fullName = "DFSG approved"; } ];
1591 license = [ pkgs.lib.licenses.mit { fullName = "DFSG approved"; } ];
@@ -9,8 +9,11
9
9
10 addopts =
10 addopts =
11 --pdbcls=IPython.terminal.debugger:TerminalPdb
11 --pdbcls=IPython.terminal.debugger:TerminalPdb
12 --strict-markers
12
13
13 markers =
14 markers =
14 vcs_operations: Mark tests depending on a running RhodeCode instance.
15 vcs_operations: Mark tests depending on a running RhodeCode instance.
15 xfail_backends: Mark tests as xfail for given backends.
16 xfail_backends: Mark tests as xfail for given backends.
16 skip_backends: Mark tests as skipped for given backends.
17 skip_backends: Mark tests as skipped for given backends.
18 backends: Mark backends
19 dbs: database markers for running tests for given DB
@@ -1,16 +1,16
1 # test related requirements
1 # test related requirements
2 pytest==3.8.2
2 pytest==4.6.5
3 py==1.6.0
3 py==1.8.0
4 pytest-cov==2.6.0
4 pytest-cov==2.7.1
5 pytest-sugar==0.9.1
5 pytest-sugar==0.9.2
6 pytest-runner==4.2.0
6 pytest-runner==5.1.0
7 pytest-profiling==1.3.0
7 pytest-profiling==1.7.0
8 pytest-timeout==1.3.2
8 pytest-timeout==1.3.3
9 gprof2dot==2017.9.19
9 gprof2dot==2017.9.19
10
10
11 mock==1.0.1
11 mock==3.0.5
12 cov-core==1.15.0
12 cov-core==1.15.0
13 coverage==4.5.3
13 coverage==4.5.4
14
14
15 webtest==2.0.33
15 webtest==2.0.33
16 beautifulsoup4==4.6.3
16 beautifulsoup4==4.6.3
@@ -31,36 +31,38
31 @pytest.fixture()
31 @pytest.fixture()
32 def make_repo_comments_factory(request):
32 def make_repo_comments_factory(request):
33
33
34 def maker(repo):
34 class Make(object):
35 user = User.get_first_super_admin()
35
36 commit = repo.scm_instance()[0]
36 def make_comments(self, repo):
37 user = User.get_first_super_admin()
38 commit = repo.scm_instance()[0]
37
39
38 commit_id = commit.raw_id
40 commit_id = commit.raw_id
39 file_0 = commit.affected_files[0]
41 file_0 = commit.affected_files[0]
40 comments = []
42 comments = []
41
43
42 # general
44 # general
43 CommentsModel().create(
45 CommentsModel().create(
44 text='General Comment', repo=repo, user=user, commit_id=commit_id,
46 text='General Comment', repo=repo, user=user, commit_id=commit_id,
45 comment_type=ChangesetComment.COMMENT_TYPE_NOTE, send_email=False)
47 comment_type=ChangesetComment.COMMENT_TYPE_NOTE, send_email=False)
46
48
47 # inline
49 # inline
48 CommentsModel().create(
50 CommentsModel().create(
49 text='Inline Comment', repo=repo, user=user, commit_id=commit_id,
51 text='Inline Comment', repo=repo, user=user, commit_id=commit_id,
50 f_path=file_0, line_no='n1',
52 f_path=file_0, line_no='n1',
51 comment_type=ChangesetComment.COMMENT_TYPE_NOTE, send_email=False)
53 comment_type=ChangesetComment.COMMENT_TYPE_NOTE, send_email=False)
52
54
53 # todo
55 # todo
54 CommentsModel().create(
56 CommentsModel().create(
55 text='INLINE TODO Comment', repo=repo, user=user, commit_id=commit_id,
57 text='INLINE TODO Comment', repo=repo, user=user, commit_id=commit_id,
56 f_path=file_0, line_no='n1',
58 f_path=file_0, line_no='n1',
57 comment_type=ChangesetComment.COMMENT_TYPE_TODO, send_email=False)
59 comment_type=ChangesetComment.COMMENT_TYPE_TODO, send_email=False)
58
60
59 @request.addfinalizer
61 @request.addfinalizer
60 def cleanup():
62 def cleanup():
61 for comment in comments:
63 for comment in comments:
62 Session().delete(comment)
64 Session().delete(comment)
63 return maker
65 return Make()
64
66
65
67
66 @pytest.mark.usefixtures("testuser_api", "app")
68 @pytest.mark.usefixtures("testuser_api", "app")
@@ -76,7 +78,7
76 make_repo_comments_factory, filters, expected_count):
78 make_repo_comments_factory, filters, expected_count):
77 commits = [{'message': 'A'}, {'message': 'B'}]
79 commits = [{'message': 'A'}, {'message': 'B'}]
78 repo = backend.create_repo(commits=commits)
80 repo = backend.create_repo(commits=commits)
79 make_repo_comments_factory(repo)
81 make_repo_comments_factory.make_comments(repo)
80
82
81 api_call_params = {'repoid': repo.repo_name,}
83 api_call_params = {'repoid': repo.repo_name,}
82 api_call_params.update(filters)
84 api_call_params.update(filters)
@@ -92,12 +94,13
92
94
93 assert len(result) == expected_count
95 assert len(result) == expected_count
94
96
95 def test_api_get_repo_comments_wrong_comment_typ(self, backend_hg):
97 def test_api_get_repo_comments_wrong_comment_type(
98 self, make_repo_comments_factory, backend_hg):
99 commits = [{'message': 'A'}, {'message': 'B'}]
100 repo = backend_hg.create_repo(commits=commits)
101 make_repo_comments_factory.make_comments(repo)
96
102
97 repo = backend_hg.create_repo()
103 api_call_params = {'repoid': repo.repo_name}
98 make_repo_comments_factory(repo)
99
100 api_call_params = {'repoid': repo.repo_name,}
101 api_call_params.update({'comment_type': 'bogus'})
104 api_call_params.update({'comment_type': 'bogus'})
102
105
103 expected = 'comment_type must be one of `{}` got {}'.format(
106 expected = 'comment_type must be one of `{}` got {}'.format(
@@ -31,10 +31,11
31
31
32
32
33 def _get_dbs_from_metafunc(metafunc):
33 def _get_dbs_from_metafunc(metafunc):
34 if hasattr(metafunc.function, 'dbs'):
34 dbs_mark = metafunc.definition.get_closest_marker('dbs')
35 # Supported backends by this test function, created from
35
36 # pytest.mark.dbs
36 if dbs_mark:
37 backends = metafunc.definition.get_closest_marker('dbs').args
37 # Supported backends by this test function, created from pytest.mark.dbs
38 backends = dbs_mark.args
38 else:
39 else:
39 backends = metafunc.config.getoption('--dbs')
40 backends = metafunc.config.getoption('--dbs')
40 return backends
41 return backends
@@ -18,16 +18,11
18 # RhodeCode Enterprise Edition, including its added features, Support services,
18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20
20
21 import os
22 import stat
23 import sys
24
25 import pytest
21 import pytest
26 from mock import Mock, patch, DEFAULT
22 from mock import Mock, patch, DEFAULT
27
23
28 import rhodecode
24 import rhodecode
29 from rhodecode.model import db, scm
25 from rhodecode.model import db, scm
30 from rhodecode.tests import no_newline_id_generator
31
26
32
27
33 def test_scm_instance_config(backend):
28 def test_scm_instance_config(backend):
@@ -35,18 +30,17
35 with patch.multiple('rhodecode.model.db.Repository',
30 with patch.multiple('rhodecode.model.db.Repository',
36 _get_instance=DEFAULT,
31 _get_instance=DEFAULT,
37 _get_instance_cached=DEFAULT) as mocks:
32 _get_instance_cached=DEFAULT) as mocks:
33
38 repo.scm_instance()
34 repo.scm_instance()
39 mocks['_get_instance'].assert_called_with(
35 mocks['_get_instance'].assert_called_with(
40 config=None, cache=False)
36 config=None, cache=False)
41
37
42 config = {'some': 'value'}
38 repo.scm_instance(vcs_full_cache=False)
43 repo.scm_instance(config=config)
44 mocks['_get_instance'].assert_called_with(
39 mocks['_get_instance'].assert_called_with(
45 config=config, cache=False)
40 config=None, cache=False)
46
41
47 with patch.dict(rhodecode.CONFIG, {'vcs_full_cache': 'true'}):
42 repo.scm_instance(vcs_full_cache=True)
48 repo.scm_instance(config=config)
43 mocks['_get_instance_cached'].assert_called()
49 mocks['_get_instance_cached'].assert_called()
50
44
51
45
52 def test_get_instance_config(backend):
46 def test_get_instance_config(backend):
@@ -30,7 +30,6
30 import time
30 import time
31 import uuid
31 import uuid
32 import dateutil.tz
32 import dateutil.tz
33 import functools
34
33
35 import mock
34 import mock
36 import pyramid.testing
35 import pyramid.testing
@@ -67,6 +66,7
67 from rhodecode.tests.fixture import Fixture
66 from rhodecode.tests.fixture import Fixture
68 from rhodecode.config import utils as config_utils
67 from rhodecode.config import utils as config_utils
69
68
69
70 def _split_comma(value):
70 def _split_comma(value):
71 return value.split(',')
71 return value.split(',')
72
72
@@ -120,14 +120,18
120
120
121
121
122 def pytest_generate_tests(metafunc):
122 def pytest_generate_tests(metafunc):
123
123 # Support test generation based on --backend parameter
124 # Support test generation based on --backend parameter
124 if 'backend_alias' in metafunc.fixturenames:
125 if 'backend_alias' in metafunc.fixturenames:
125 backends = get_backends_from_metafunc(metafunc)
126 backends = get_backends_from_metafunc(metafunc)
126 scope = None
127 scope = None
127 if not backends:
128 if not backends:
128 pytest.skip("Not enabled for any of selected backends")
129 pytest.skip("Not enabled for any of selected backends")
130
129 metafunc.parametrize('backend_alias', backends, scope=scope)
131 metafunc.parametrize('backend_alias', backends, scope=scope)
130 elif hasattr(metafunc.function, 'backends'):
132
133 backend_mark = metafunc.definition.get_closest_marker('backends')
134 if backend_mark:
131 backends = get_backends_from_metafunc(metafunc)
135 backends = get_backends_from_metafunc(metafunc)
132 if not backends:
136 if not backends:
133 pytest.skip("Not enabled for any of selected backends")
137 pytest.skip("Not enabled for any of selected backends")
@@ -135,10 +139,11
135
139
136 def get_backends_from_metafunc(metafunc):
140 def get_backends_from_metafunc(metafunc):
137 requested_backends = set(metafunc.config.getoption('--backends'))
141 requested_backends = set(metafunc.config.getoption('--backends'))
138 if hasattr(metafunc.function, 'backends'):
142 backend_mark = metafunc.definition.get_closest_marker('backends')
143 if backend_mark:
139 # Supported backends by this test function, created from
144 # Supported backends by this test function, created from
140 # pytest.mark.backends
145 # pytest.mark.backends
141 backends = metafunc.definition.get_closest_marker('backends').args
146 backends = backend_mark.args
142 elif hasattr(metafunc.cls, 'backend_alias'):
147 elif hasattr(metafunc.cls, 'backend_alias'):
143 # Support class attribute "backend_alias", this is mainly
148 # Support class attribute "backend_alias", this is mainly
144 # for legacy reasons for tests not yet using pytest.mark.backends
149 # for legacy reasons for tests not yet using pytest.mark.backends
@@ -1810,17 +1815,3
1810 fixture.destroy_repo_group(parent_group)
1815 fixture.destroy_repo_group(parent_group)
1811
1816
1812 return zombie_group, parent_group, child_group
1817 return zombie_group, parent_group, child_group
1813
1814
1815 @pytest.fixture(scope="session")
1816 def tmp_path_factory(request):
1817 """Return a :class:`_pytest.tmpdir.TempPathFactory` instance for the test session.
1818 """
1819
1820 class TempPathFactory:
1821
1822 def mktemp(self, basename):
1823 import tempfile
1824 return tempfile.mktemp(basename)
1825
1826 return TempPathFactory()
@@ -48,21 +48,21
48 self.repo = GitRepository(TEST_GIT_REPO, bare=True)
48 self.repo = GitRepository(TEST_GIT_REPO, bare=True)
49 self.repo.count()
49 self.repo.count()
50
50
51 def get_clone_repo(self, tmp_path_factory):
51 def get_clone_repo(self, tmpdir):
52 """
52 """
53 Return a non bare clone of the base repo.
53 Return a non bare clone of the base repo.
54 """
54 """
55 clone_path = tmp_path_factory.mktemp('clone-url')
55 clone_path = str(tmpdir.join('clone-repo'))
56 repo_clone = GitRepository(
56 repo_clone = GitRepository(
57 clone_path, create=True, src_url=self.repo.path, bare=False)
57 clone_path, create=True, src_url=self.repo.path, bare=False)
58
58
59 return repo_clone
59 return repo_clone
60
60
61 def get_empty_repo(self, tmp_path_factory, bare=False):
61 def get_empty_repo(self, tmpdir, bare=False):
62 """
62 """
63 Return a non bare empty repo.
63 Return a non bare empty repo.
64 """
64 """
65 clone_path = tmp_path_factory.mktemp('empty-repo')
65 clone_path = str(tmpdir.join('empty-repo'))
66 return GitRepository(clone_path, create=True, bare=bare)
66 return GitRepository(clone_path, create=True, bare=bare)
67
67
68 def test_wrong_repo_path(self):
68 def test_wrong_repo_path(self):
@@ -72,7 +72,7
72
72
73 def test_repo_clone(self, tmp_path_factory):
73 def test_repo_clone(self, tmp_path_factory):
74 repo = GitRepository(TEST_GIT_REPO)
74 repo = GitRepository(TEST_GIT_REPO)
75 clone_path = tmp_path_factory.mktemp('_') + '_' + TEST_GIT_REPO_CLONE
75 clone_path = '{}_{}'.format(tmp_path_factory.mktemp('_'), TEST_GIT_REPO_CLONE)
76 repo_clone = GitRepository(
76 repo_clone = GitRepository(
77 clone_path,
77 clone_path,
78 src_url=TEST_GIT_REPO, create=True, do_workspace_checkout=True)
78 src_url=TEST_GIT_REPO, create=True, do_workspace_checkout=True)
@@ -90,7 +90,7
90
90
91 def test_repo_clone_with_update(self, tmp_path_factory):
91 def test_repo_clone_with_update(self, tmp_path_factory):
92 repo = GitRepository(TEST_GIT_REPO)
92 repo = GitRepository(TEST_GIT_REPO)
93 clone_path = tmp_path_factory.mktemp('_') + '_' + TEST_GIT_REPO_CLONE + '_update'
93 clone_path = '{}_{}_update'.format(tmp_path_factory.mktemp('_'), TEST_GIT_REPO_CLONE)
94
94
95 repo_clone = GitRepository(
95 repo_clone = GitRepository(
96 clone_path,
96 clone_path,
@@ -103,7 +103,7
103
103
104 def test_repo_clone_without_update(self, tmp_path_factory):
104 def test_repo_clone_without_update(self, tmp_path_factory):
105 repo = GitRepository(TEST_GIT_REPO)
105 repo = GitRepository(TEST_GIT_REPO)
106 clone_path = tmp_path_factory.mktemp('_') + '_' + TEST_GIT_REPO_CLONE + '_without_update'
106 clone_path = '{}_{}_without_update'.format(tmp_path_factory.mktemp('_'), TEST_GIT_REPO_CLONE)
107 repo_clone = GitRepository(
107 repo_clone = GitRepository(
108 clone_path,
108 clone_path,
109 create=True, src_url=TEST_GIT_REPO, do_workspace_checkout=False)
109 create=True, src_url=TEST_GIT_REPO, do_workspace_checkout=False)
@@ -116,7 +116,7
116
116
117 def test_repo_clone_into_bare_repo(self, tmp_path_factory):
117 def test_repo_clone_into_bare_repo(self, tmp_path_factory):
118 repo = GitRepository(TEST_GIT_REPO)
118 repo = GitRepository(TEST_GIT_REPO)
119 clone_path = tmp_path_factory.mktemp('_') + '_' + TEST_GIT_REPO_CLONE + '_bare.git'
119 clone_path = '{}_{}_bare.git'.format(tmp_path_factory.mktemp('_'), TEST_GIT_REPO_CLONE)
120 repo_clone = GitRepository(
120 repo_clone = GitRepository(
121 clone_path, create=True, src_url=repo.path, bare=True)
121 clone_path, create=True, src_url=repo.path, bare=True)
122 assert repo_clone.bare
122 assert repo_clone.bare
@@ -258,8 +258,8
258 def test_head(self):
258 def test_head(self):
259 assert self.repo.head == self.repo.get_commit().raw_id
259 assert self.repo.head == self.repo.get_commit().raw_id
260
260
261 def test_checkout_with_create(self, tmp_path_factory):
261 def test_checkout_with_create(self, tmpdir):
262 repo_clone = self.get_clone_repo(tmp_path_factory)
262 repo_clone = self.get_clone_repo(tmpdir)
263
263
264 new_branch = 'new_branch'
264 new_branch = 'new_branch'
265 assert repo_clone._current_branch() == 'master'
265 assert repo_clone._current_branch() == 'master'
@@ -271,22 +271,22
271 assert set(repo_clone.branches) == {'master', new_branch}
271 assert set(repo_clone.branches) == {'master', new_branch}
272 assert repo_clone._current_branch() == new_branch
272 assert repo_clone._current_branch() == new_branch
273
273
274 def test_checkout(self, tmp_path_factory):
274 def test_checkout(self, tmpdir):
275 repo_clone = self.get_clone_repo(tmp_path_factory)
275 repo_clone = self.get_clone_repo(tmpdir)
276
276
277 repo_clone._checkout('new_branch', create=True)
277 repo_clone._checkout('new_branch', create=True)
278 repo_clone._checkout('master')
278 repo_clone._checkout('master')
279
279
280 assert repo_clone._current_branch() == 'master'
280 assert repo_clone._current_branch() == 'master'
281
281
282 def test_checkout_same_branch(self, tmp_path_factory):
282 def test_checkout_same_branch(self, tmpdir):
283 repo_clone = self.get_clone_repo(tmp_path_factory)
283 repo_clone = self.get_clone_repo(tmpdir)
284
284
285 repo_clone._checkout('master')
285 repo_clone._checkout('master')
286 assert repo_clone._current_branch() == 'master'
286 assert repo_clone._current_branch() == 'master'
287
287
288 def test_checkout_branch_already_exists(self, tmp_path_factory):
288 def test_checkout_branch_already_exists(self, tmpdir):
289 repo_clone = self.get_clone_repo(tmp_path_factory)
289 repo_clone = self.get_clone_repo(tmpdir)
290
290
291 with pytest.raises(RepositoryError):
291 with pytest.raises(RepositoryError):
292 repo_clone._checkout('master', create=True)
292 repo_clone._checkout('master', create=True)
@@ -299,32 +299,32
299 with pytest.raises(RepositoryError):
299 with pytest.raises(RepositoryError):
300 self.repo._current_branch()
300 self.repo._current_branch()
301
301
302 def test_current_branch_empty_repo(self, tmp_path_factory):
302 def test_current_branch_empty_repo(self, tmpdir):
303 repo = self.get_empty_repo(tmp_path_factory)
303 repo = self.get_empty_repo(tmpdir)
304 assert repo._current_branch() is None
304 assert repo._current_branch() is None
305
305
306 def test_local_clone(self, tmp_path_factory):
306 def test_local_clone(self, tmp_path_factory):
307 clone_path = tmp_path_factory.mktemp('test-local-clone')
307 clone_path = str(tmp_path_factory.mktemp('test-local-clone'))
308 self.repo._local_clone(clone_path, 'master')
308 self.repo._local_clone(clone_path, 'master')
309 repo_clone = GitRepository(clone_path)
309 repo_clone = GitRepository(clone_path)
310
310
311 assert self.repo.commit_ids == repo_clone.commit_ids
311 assert self.repo.commit_ids == repo_clone.commit_ids
312
312
313 def test_local_clone_with_specific_branch(self, tmp_path_factory):
313 def test_local_clone_with_specific_branch(self, tmpdir):
314 source_repo = self.get_clone_repo(tmp_path_factory)
314 source_repo = self.get_clone_repo(tmpdir)
315
315
316 # Create a new branch in source repo
316 # Create a new branch in source repo
317 new_branch_commit = source_repo.commit_ids[-3]
317 new_branch_commit = source_repo.commit_ids[-3]
318 source_repo._checkout(new_branch_commit)
318 source_repo._checkout(new_branch_commit)
319 source_repo._checkout('new_branch', create=True)
319 source_repo._checkout('new_branch', create=True)
320
320
321 clone_path = tmp_path_factory.mktemp('git-clone-path-1')
321 clone_path = str(tmpdir.join('git-clone-path-1'))
322 source_repo._local_clone(clone_path, 'new_branch')
322 source_repo._local_clone(clone_path, 'new_branch')
323 repo_clone = GitRepository(clone_path)
323 repo_clone = GitRepository(clone_path)
324
324
325 assert source_repo.commit_ids[:-3 + 1] == repo_clone.commit_ids
325 assert source_repo.commit_ids[:-3 + 1] == repo_clone.commit_ids
326
326
327 clone_path = tmp_path_factory.mktemp('git-clone-path-2')
327 clone_path = str(tmpdir.join('git-clone-path-2'))
328 source_repo._local_clone(clone_path, 'master')
328 source_repo._local_clone(clone_path, 'master')
329 repo_clone = GitRepository(clone_path)
329 repo_clone = GitRepository(clone_path)
330
330
@@ -334,9 +334,9
334 with pytest.raises(RepositoryError):
334 with pytest.raises(RepositoryError):
335 self.repo._local_clone(self.repo.path, 'master')
335 self.repo._local_clone(self.repo.path, 'master')
336
336
337 def test_local_fetch(self, tmp_path_factory):
337 def test_local_fetch(self, tmpdir):
338 target_repo = self.get_empty_repo(tmp_path_factory)
338 target_repo = self.get_empty_repo(tmpdir)
339 source_repo = self.get_clone_repo(tmp_path_factory)
339 source_repo = self.get_clone_repo(tmpdir)
340
340
341 # Create a new branch in source repo
341 # Create a new branch in source repo
342 master_commit = source_repo.commit_ids[-1]
342 master_commit = source_repo.commit_ids[-1]
@@ -350,8 +350,8
350 target_repo._local_fetch(source_repo.path, 'master')
350 target_repo._local_fetch(source_repo.path, 'master')
351 assert target_repo._last_fetch_heads() == [master_commit]
351 assert target_repo._last_fetch_heads() == [master_commit]
352
352
353 def test_local_fetch_from_bare_repo(self, tmp_path_factory):
353 def test_local_fetch_from_bare_repo(self, tmpdir):
354 target_repo = self.get_empty_repo(tmp_path_factory)
354 target_repo = self.get_empty_repo(tmpdir)
355 target_repo._local_fetch(self.repo.path, 'master')
355 target_repo._local_fetch(self.repo.path, 'master')
356
356
357 master_commit = self.repo.commit_ids[-1]
357 master_commit = self.repo.commit_ids[-1]
@@ -361,15 +361,15