2018-01-04 13:22:14 +00:00
|
|
|
import pathlib
|
2017-02-09 13:06:36 +00:00
|
|
|
import runpy
|
2017-12-27 20:46:52 +00:00
|
|
|
import subprocess
|
2018-06-02 19:37:44 +00:00
|
|
|
import sys
|
2017-12-27 20:46:52 +00:00
|
|
|
from unittest import mock
|
2017-02-09 13:06:36 +00:00
|
|
|
|
|
|
|
from mitmproxy import version
|
|
|
|
|
|
|
|
|
|
|
|
def test_version(capsys):
|
2018-01-04 13:22:14 +00:00
|
|
|
here = pathlib.Path(__file__).absolute().parent
|
|
|
|
version_file = here / ".." / ".." / "mitmproxy" / "version.py"
|
|
|
|
runpy.run_path(str(version_file), run_name='__main__')
|
2017-02-09 13:06:36 +00:00
|
|
|
stdout, stderr = capsys.readouterr()
|
|
|
|
assert len(stdout) > 0
|
|
|
|
assert stdout.strip() == version.VERSION
|
2017-12-27 20:46:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_get_version():
|
2018-06-02 19:37:44 +00:00
|
|
|
version.VERSION = "3.0.0rc2"
|
2017-12-27 20:46:52 +00:00
|
|
|
|
|
|
|
with mock.patch('subprocess.check_output') as m:
|
|
|
|
m.return_value = b"tag-0-cafecafe"
|
2018-06-02 19:37:44 +00:00
|
|
|
assert version.get_dev_version() == "3.0.0rc2"
|
|
|
|
|
|
|
|
sys.frozen = True
|
|
|
|
assert version.get_dev_version() == "3.0.0rc2 binary"
|
|
|
|
sys.frozen = False
|
2017-12-27 20:46:52 +00:00
|
|
|
|
|
|
|
m.return_value = b"tag-2-cafecafe"
|
2018-06-02 19:37:44 +00:00
|
|
|
assert version.get_dev_version() == "3.0.0rc2 (+2, commit cafecaf)"
|
2017-12-27 20:46:52 +00:00
|
|
|
|
2019-12-21 01:18:17 +00:00
|
|
|
m.side_effect = subprocess.CalledProcessError(-1, 'git describe --tags --long')
|
2018-06-02 19:37:44 +00:00
|
|
|
assert version.get_dev_version() == "3.0.0rc2"
|