@@ -26,25 +26,27 @@ def simulate_get_version(file, app_version=False, sem_ver=False, release=False,
2626 return run (["python" , "src/pybump.py" , "get" , "--file" , file ], stdout = PIPE , stderr = PIPE )
2727
2828
29- def simulate_set_version (file , version = '' , app_version = False , auto = False ):
29+ def simulate_set_version (file , version = '' , app_version = False , auto = False , metadata = False ):
3030 """
3131 execute sub process to simulate real app execution,
3232 set new version to a file
3333 if auto is True, auto add git branch / hash
34+ if metadata is True (with auto), set SHA as metadata (+sha) instead of release (-sha)
3435 if app_version is True, then add the --app-version flag to execution
3536 :param file: string
3637 :param version: string
3738 :param app_version: boolean
3839 :param auto: boolean
40+ :param metadata: boolean
3941 :return: CompletedProcess object
4042 """
4143 if auto :
44+ cmd = ["python" , "src/pybump.py" , "set" , "--file" , file , "--auto" ]
45+ if metadata :
46+ cmd .append ("--metadata" )
4247 if app_version :
43- return run (["python" , "src/pybump.py" , "set" , "--file" , file , "--auto" , "--app-version" ],
44- stdout = PIPE , stderr = PIPE )
45- else :
46- return run (["python" , "src/pybump.py" , "set" , "--file" , file , "--auto" ],
47- stdout = PIPE , stderr = PIPE )
48+ cmd .append ("--app-version" )
49+ return run (cmd , stdout = PIPE , stderr = PIPE )
4850 else :
4951 if app_version :
5052 return run (["python" , "src/pybump.py" , "set" , "--file" , file , "--set-version" , version , "--app-version" ],
@@ -239,16 +241,31 @@ def test_get_flags(self):
239241
240242 def test_set_flags (self ):
241243 ################################################
242- # simulate the 'set' command with version prefix
244+ # simulate the 'set' command with --auto flag
243245 ################################################
244246 # first set test_valid_setup.py a simple version
245247 simulate_set_version ("test/test_content_files/test_valid_setup.py" , version = "1.0.1" )
246248
249+ # test --auto sets release (-sha)
247250 test_set_auto = simulate_set_version ("test/test_content_files/test_valid_setup.py" , auto = True )
248251 self .assertRegex (test_set_auto .stdout .decode ('utf-8' ).strip (),
249252 r'\b1.0.1-[0-9a-f]{40}\b' ,
250253 msg = "test that 'test_set_auto' contains an hexadecimal string with exactly 40 characters" )
251254
255+ ########################################################
256+ # simulate the 'set' command with --auto --metadata flag
257+ ########################################################
258+ # reset to simple version
259+ simulate_set_version ("test/test_content_files/test_valid_setup.py" , version = "2.0.0" )
260+
261+ # test --auto --metadata sets metadata (+sha) instead of release (-sha)
262+ test_set_auto_metadata = simulate_set_version ("test/test_content_files/test_valid_setup.py" ,
263+ auto = True , metadata = True )
264+ self .assertRegex (test_set_auto_metadata .stdout .decode ('utf-8' ).strip (),
265+ r'\b2.0.0\+[0-9a-f]{40}\b' ,
266+ msg = "test that '--auto --metadata' sets SHA as metadata (+sha), "
267+ "output should match 2.0.0+<40-char-hex>" )
268+
252269 # test invalid version set
253270 test_set_auto = simulate_set_version ("test/test_content_files/test_valid_setup.py" , version = 'V123.x.4' )
254271 self .assertEqual ('Invalid semantic version format: V123.x.4\n Make sure to comply with https://semver.org/ '
0 commit comments