@@ -106,6 +106,7 @@ def test_fixture(capsys, server):
106106 assert depotfile_to_content == {
107107 "//depot/file.txt" : "Hello World\n " ,
108108 "//stream-depot/main/file.txt" : "Hello Stream World\n " ,
109+ "//stream-depot/main/file_2.txt" : "file_2\n " ,
109110 "//stream-depot/dev/file.txt" : "Hello Stream World (dev)\n " ,
110111 }
111112
@@ -143,6 +144,11 @@ def test_fixture(capsys, server):
143144 'action' : ['edit' ],
144145 'depotFile' : ['//stream-depot/dev/file.txt' ],
145146 'desc' : 'Update contents of //stream-depot/dev/file.txt\n '
147+ },
148+ '9' : {
149+ 'action' : ['add' ],
150+ 'depotFile' : ['//stream-depot/main/file_2.txt' ],
151+ 'desc' : 'file_2.txt - exists in main but not dev\n '
146152 }
147153 }
148154
@@ -188,11 +194,12 @@ def test_fixture(capsys, server):
188194
189195def test_head (server , tmpdir ):
190196 """Test resolve of HEAD changelist"""
191- repo = P4Repo (root = tmpdir )
192- assert repo .head () == "@6" , "Unexpected global HEAD revision"
197+ # workspace with no changes in view defaults to global view
198+ repo = P4Repo (root = tmpdir , view = "//depot/empty_dir/... empty_dir/..." )
199+ assert repo .head () == "@9" , "Unexpected global HEAD revision"
193200
194- repo = P4Repo (root = tmpdir , stream = '//stream-depot/main ' )
195- assert repo .head () == "@2 " , "Unexpected HEAD revision for stream"
201+ repo = P4Repo (root = tmpdir , stream = '//stream-depot/dev ' )
202+ assert repo .head () == "@8 " , "Unexpected HEAD revision for stream"
196203
197204 repo = P4Repo (root = tmpdir , stream = '//stream-depot/idontexist' )
198205 with pytest .raises (Exception , match = r"Stream '//stream-depot/idontexist' doesn't exist." ):
@@ -413,16 +420,42 @@ def test_stream_switching(server, tmpdir):
413420 repo = P4Repo (root = tmpdir , stream = '//stream-depot/main' )
414421 synced = repo .sync ()
415422 assert len (synced ) > 0 , "Didn't sync any files"
423+ assert set (os .listdir (tmpdir )) == set ([
424+ "file.txt" , "file_2.txt" , "p4config" ])
416425 with open (os .path .join (tmpdir , "file.txt" )) as content :
417426 assert content .read () == "Hello Stream World\n " , "Unexpected content in workspace file"
418427
419428 # Re-use the same checkout directory, but switch streams
420429 repo = P4Repo (root = tmpdir , stream = '//stream-depot/dev' )
421430 repo .sync ()
422431 assert len (synced ) > 0 , "Didn't sync any files"
432+ assert set (os .listdir (tmpdir )) == set ([
433+ "file.txt" , "p4config" ]) # file_2.txt was de-synced
423434 with open (os .path .join (tmpdir , "file.txt" )) as content :
424435 assert content .read () == "Hello Stream World (dev)\n " , "Unexpected content in workspace file"
425436
437+ def test_stream_switching_migration (server , tmpdir ):
438+ """Test stream-switching and client migration simultaneously"""
439+ repo = P4Repo (root = tmpdir , stream = '//stream-depot/main' )
440+ synced = repo .sync ()
441+ assert len (synced ) > 0 , "Didn't sync any files"
442+ assert set (os .listdir (tmpdir )) == set ([
443+ "file.txt" , "file_2.txt" , "p4config" ])
444+ with open (os .path .join (tmpdir , "file.txt" )) as content :
445+ assert content .read () == "Hello Stream World\n " , "Unexpected content in workspace file"
446+
447+ with tempfile .TemporaryDirectory (prefix = "bk-p4-test-" ) as second_client :
448+ copytree (tmpdir , second_client )
449+ # Client names include path on disk, so this creates a new unique client
450+ # Re-use the same checkout directory and switch streams at the same time
451+ repo = P4Repo (root = second_client , stream = '//stream-depot/dev' )
452+ repo .sync ()
453+ assert len (synced ) > 0 , "Didn't sync any files"
454+ assert set (os .listdir (second_client )) == set ([
455+ "file.txt" , "p4config" ]) # file_2.txt was de-synced
456+ with open (os .path .join (second_client , "file.txt" )) as content :
457+ assert content .read () == "Hello Stream World (dev)\n " , "Unexpected content in workspace file"
458+
426459
427460# def test_live_server():
428461# """Reproduce production issues quickly by writing tests which run against a real server"""
0 commit comments