tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_context_manager.py (1190B)


      1 # This Source Code Form is subject to the terms of the Mozilla Public
      2 # License, v. 2.0. If a copy of the MPL was not distributed with this
      3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
      4 
      5 import mozunit
      6 
      7 from mozversioncontrol import get_repository_object
      8 
      9 
     10 def test_context_manager(repo):
     11    cmd = {
     12        "git": ["show", "--no-patch"],
     13        "hg": ["tip"],
     14        # For jj, remove most of the header to avoid relative timestamps (one
     15        # output might say "(now)", the next "(1 second ago)" for the same
     16        # timestamp.)
     17        "jj": ["show", "@-", "--template", "description ++ '\\n'"],
     18        "src": ["echo", "src"],
     19    }[repo.vcs]
     20 
     21    vcs = get_repository_object(repo.dir)
     22    output_subprocess = vcs._run(*cmd)
     23    if repo.vcs == "hg":
     24        assert vcs._client.server is None
     25    if repo.vcs != "src":
     26        assert "Initial commit" in output_subprocess
     27 
     28    with vcs:
     29        if repo.vcs == "hg":
     30            assert vcs._client.server is not None
     31        output_client = vcs._run(*cmd)
     32 
     33    if repo.vcs == "hg":
     34        assert vcs._client.server is None
     35    assert output_subprocess == output_client
     36 
     37 
     38 if __name__ == "__main__":
     39    mozunit.main()