tor-browser

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

conftest.py (1686B)


      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 os
      6 import sys
      7 from argparse import Namespace
      8 
      9 import pytest
     10 
     11 from mozlint import LintRoller
     12 
     13 here = os.path.abspath(os.path.dirname(__file__))
     14 
     15 
     16 @pytest.fixture
     17 def lint(request):
     18    lintargs = getattr(request.module, "lintargs", {})
     19    lint = LintRoller(root=here, **lintargs)
     20 
     21    # Add a few super powers to our lint instance
     22    def mock_vcs(files):
     23        def _fake_vcs_files(*args, **kwargs):
     24            return files
     25 
     26        setattr(lint.vcs, "get_changed_files", _fake_vcs_files)
     27        setattr(lint.vcs, "get_outgoing_files", _fake_vcs_files)
     28 
     29    setattr(lint, "vcs", Namespace())
     30    setattr(lint, "mock_vcs", mock_vcs)
     31    return lint
     32 
     33 
     34 @pytest.fixture(scope="session")
     35 def filedir():
     36    return os.path.join(here, "files")
     37 
     38 
     39 @pytest.fixture(scope="module")
     40 def files(filedir, request):
     41    suffix_filter = getattr(request.module, "files", [""])
     42    return [
     43        os.path.join(filedir, p)
     44        for p in os.listdir(filedir)
     45        if any(p.endswith(suffix) for suffix in suffix_filter)
     46    ]
     47 
     48 
     49 @pytest.fixture(scope="session")
     50 def lintdir():
     51    lintdir = os.path.join(here, "linters")
     52    sys.path.insert(0, lintdir)
     53    return lintdir
     54 
     55 
     56 @pytest.fixture(scope="module")
     57 def linters(lintdir):
     58    def inner(*names):
     59        return [
     60            os.path.join(lintdir, p)
     61            for p in os.listdir(lintdir)
     62            if any(os.path.splitext(p)[0] == name for name in names)
     63            if os.path.splitext(p)[1] == ".yml"
     64        ]
     65 
     66    return inner