misc: decode debian package version number (#48466)

This commit is contained in:
Frédéric Péters 2020-11-15 19:34:24 +01:00
parent f329c8b057
commit aef2d25d77
2 changed files with 31 additions and 1 deletions

View File

@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
import json
import mock
import pytest
import os
import pickle
@ -590,3 +591,32 @@ def test_related_field_repr():
parent_field=StringField(label='bar'))
assert 'foo' in repr(related_field)
assert 'bar' in repr(related_field)
def test_find_vc_version():
import wcs.qommon.admin.menu
with mock.patch('os.path.exists') as os_path_exists, mock.patch('subprocess.Popen') as popen:
def mocked_os_path_exists(path):
return bool(not path.endswith('setup.py'))
os_path_exists.side_effect = mocked_os_path_exists
def mocked_popen(*args, **kwargs):
class Process:
returncode = 0
def communicate(self):
return (b'''Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-==============-===============-============-=================================================
ii wcs 5.71-1~eob100+1 all web application to design and set up online forms
''', '')
return Process()
popen.side_effect = mocked_popen
version = wcs.qommon.admin.menu._find_vc_version()
assert version == 'wcs 5.71-1~eob100+1 (Debian)'

View File

@ -48,7 +48,7 @@ def _find_vc_version():
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
version = process.communicate()[0].splitlines()[-1].split()[2]
if process.returncode == 0:
return "%s %s (Debian)" % (package, version)
return "%s %s (Debian)" % (package, version.decode())
except:
pass
return None