1
1
import os
2
2
import os .path
3
+ import subprocess
3
4
import sys
4
5
5
6
import stackinabox
@@ -11,7 +12,6 @@ class TestVersionMatch(base.TestCase):
11
12
def setUp (self ):
12
13
super (TestVersionMatch , self ).setUp ()
13
14
self .local_directory = os .path .dirname (__file__ )
14
- self .setup_py = '{0}/../setup.py' .format (self .local_directory )
15
15
self .doc_conf = '{0}/../../docs/conf.py' .format (self .local_directory )
16
16
17
17
def tearDown (self ):
@@ -27,14 +27,25 @@ def make_version_source():
27
27
def test_version_match (self ):
28
28
version_source = self .make_version_source ()
29
29
30
+ # read the data from `pip show <package>` to get the version
31
+ # as seen by the installer
30
32
version_setup = None
31
- with open (self .setup_py , 'rt' ) as input_data :
32
- for line in input_data :
33
- ln = line .strip ()
34
- if ln .startswith ('version=' ):
35
- ln_parts = ln .replace ("'" , '' , 2 ).replace (',' , '' )
36
- version_setup = ln_parts .split ('=' )[1 ]
33
+ cmd = ["pip" , "show" , "stackinabox" ]
34
+ pip_freeze = subprocess .Popen (cmd , stdout = subprocess .PIPE )
35
+ output , error = pip_freeze .communicate ()
36
+ if error is None :
37
+ output_lines = output .decode ('utf-8' ).split ("\n " )
38
+ print (f"Read pip freeze data:\n { output_lines } \n " )
39
+ for line in output_lines :
40
+ line_data = line .split (':' )
41
+ key = line_data [0 ]
42
+ value = ':' .join (line_data [1 :]).strip ()
43
+ print (f"\t Line Key: { key } - Value: { value } " )
44
+ if key .lower () == "version" :
45
+ version_setup = value
37
46
break
47
+ else :
48
+ self .fail (f"Unable to retrieve version data - error: { error } " )
38
49
39
50
self .assertEqual (version_source , version_setup )
40
51
0 commit comments