tor-browser

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

test_update.py (1750B)


      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 from subprocess import CalledProcessError
      6 
      7 import mozunit
      8 import pytest
      9 
     10 from mozversioncontrol import get_repository_object
     11 
     12 STEPS = {
     13    "hg": [
     14        """
     15        echo "bar" >> bar
     16        echo "baz" > foo
     17        hg commit -m "second commit"
     18        """,
     19        """
     20        echo "foobar" > foo
     21        """,
     22    ],
     23    "git": [
     24        """
     25        echo "bar" >> bar
     26        echo "baz" > foo
     27        git add *
     28        git commit -m "second commit"
     29        """,
     30        """
     31        echo "foobar" > foo
     32        """,
     33    ],
     34    "jj": [
     35        """
     36        echo "bar" >> bar
     37        echo "baz" > foo
     38        jj commit -m "second commit"
     39        """,
     40        """
     41        echo "foobar" > foo
     42        """,
     43    ],
     44 }
     45 
     46 
     47 def test_update(repo):
     48    vcs = get_repository_object(repo.dir)
     49    rev0 = vcs.head_ref
     50 
     51    # Create a commit with modified `foo` and `bar`.
     52    repo.execute_next_step()
     53    rev1 = vcs.head_ref
     54    assert rev0 != rev1
     55 
     56    if repo.vcs == "hg":
     57        vcs.update(".~1")
     58    elif repo.vcs == "git":
     59        vcs.update("HEAD~1")
     60    elif repo.vcs == "jj":
     61        vcs.update("@--")
     62    assert vcs.head_ref == rev0
     63 
     64    vcs.update(rev1)
     65    assert vcs.head_ref == rev1
     66 
     67    # Modify `foo` and update. Should fail with dirty working directory.
     68    repo.execute_next_step()
     69    if repo.vcs != "jj":
     70        with pytest.raises(CalledProcessError):
     71            vcs.update(rev0)
     72        assert vcs.head_ref == rev1
     73    else:
     74        # jj doesn't have a "dirty working directory".
     75        pass
     76 
     77 
     78 if __name__ == "__main__":
     79    mozunit.main()