tor-browser

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

test_versions.py (2931B)


      1 import mozunit
      2 import pytest
      3 
      4 from mozrelease.versions import (
      5    AncientMozillaVersion,
      6    ModernMozillaVersion,
      7    MozillaVersion,
      8 )
      9 
     10 ALL_VERSIONS = [  # Keep this sorted
     11    "3.0",
     12    "3.0.1",
     13    "3.0.2",
     14    "3.0.3",
     15    "3.0.4",
     16    "3.0.5",
     17    "3.0.6",
     18    "3.0.7",
     19    "3.0.8",
     20    "3.0.9",
     21    "3.0.10",
     22    "3.0.11",
     23    "3.0.12",
     24    "3.0.13",
     25    "3.0.14",
     26    "3.0.15",
     27    "3.0.16",
     28    "3.0.17",
     29    "3.0.18",
     30    "3.0.19",
     31    "3.1b1",
     32    "3.1b2",
     33    "3.1b3",
     34    "3.5b4",
     35    "3.5b99",
     36    "3.5rc1",
     37    "3.5rc2",
     38    "3.5rc3",
     39    "3.5",
     40    "3.5.1",
     41    "3.5.2",
     42    "3.5.3",
     43    "3.5.4",
     44    "3.5.5",
     45    "3.5.6",
     46    "3.5.7",
     47    "3.5.8",
     48    "3.5.9",
     49    "3.5.10",
     50    # ... Start skipping around...
     51    "4.0b9",
     52    "10.0.2esr",
     53    "10.0.3esr",
     54    "32.0",
     55    "49.0a1",
     56    "49.0a2",
     57    "59.0",
     58    "60.0",
     59    "60.0esr",
     60    "60.0.1esr",
     61    "60.1",
     62    "60.1esr",
     63    "61.0",
     64 ]
     65 
     66 
     67 @pytest.fixture(
     68    scope="function",
     69    params=range(len(ALL_VERSIONS) - 1),
     70    ids=lambda x: f"{ALL_VERSIONS[x]}, {ALL_VERSIONS[x + 1]}",
     71 )
     72 def comparable_versions(request):
     73    index = request.param
     74    return ALL_VERSIONS[index], ALL_VERSIONS[index + 1]
     75 
     76 
     77 @pytest.mark.parametrize("version", ALL_VERSIONS)
     78 def test_versions_parseable(version):
     79    """Test that we can parse previously shipped versions.
     80 
     81    We only test 3.0 and up, since we never generate updates against
     82    versions that old."""
     83    assert MozillaVersion(version) is not None
     84 
     85 
     86 def test_versions_compare_less(comparable_versions):
     87    """Test that versions properly compare in order."""
     88    smaller_version, larger_version = comparable_versions
     89    assert MozillaVersion(smaller_version) < MozillaVersion(larger_version)
     90 
     91 
     92 def test_versions_compare_greater(comparable_versions):
     93    """Test that versions properly compare in order."""
     94    smaller_version, larger_version = comparable_versions
     95    assert MozillaVersion(larger_version) > MozillaVersion(smaller_version)
     96 
     97 
     98 def test_ModernMozillaVersion():
     99    """Test properties specific to ModernMozillaVersion"""
    100    assert isinstance(MozillaVersion("1.2.4"), ModernMozillaVersion)
    101    assert isinstance(MozillaVersion("1.2.4rc3"), ModernMozillaVersion)
    102    assert MozillaVersion("1.2rc3") == MozillaVersion("1.2.0rc3")
    103 
    104 
    105 def test_AncientMozillaVersion():
    106    """Test properties specific to AncientMozillaVersion"""
    107    assert isinstance(MozillaVersion("1.2.0.4"), AncientMozillaVersion)
    108    assert isinstance(MozillaVersion("1.2.0.4pre1"), AncientMozillaVersion)
    109    assert MozillaVersion("1.2pre1") == MozillaVersion("1.2.0pre1")
    110    assert MozillaVersion("1.2.0.4pre1") == MozillaVersion("1.2.4pre1")
    111 
    112 
    113 @pytest.mark.parametrize("version", ALL_VERSIONS)
    114 def test_versions_compare_equal(version):
    115    """Test that versions properly compare as equal through multiple passes."""
    116    assert MozillaVersion(version) == MozillaVersion(version)
    117 
    118 
    119 if __name__ == "__main__":
    120    mozunit.main()