Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run tests in /tmp #374

Merged
merged 5 commits into from
Nov 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ jobs:
with:
ref: ${{ github.event.pull_request.head.sha }} # Checkout pull request HEAD commit instead of merge commit

# Because gitlint is a tool that uses git itself under the hood, we remove git tracking from the checked out
# code by temporarily renaming the .git directory.
# This is to ensure that the tests don't have a dependency on the version control of gitlint itself.
- name: Temporarily remove git version control from code
run: mv .git ._git

- name: Setup python
uses: actions/[email protected]
with:
Expand Down Expand Up @@ -85,10 +79,6 @@ jobs:
# with:
# github-token: ${{ secrets.GITHUB_TOKEN }}

# Re-add git version control so we can run gitlint on itself.
- name: Re-add git version control to code
run: mv ._git .git

# Run gitlint. Skip during PR runs, since PR commit messages are transient and usually full of gitlint violations.
# PRs get squashed and get a proper commit message during merge.
- name: Gitlint check
Expand Down
18 changes: 18 additions & 0 deletions gitlint-core/gitlint/tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,28 @@ class BaseTestCase(unittest.TestCase):
# In case of assert failures, print the full error message
maxDiff = None

# Working directory in which tests in this class are executed
working_dir = None
# Originally working dir when the test was started
original_working_dir = None

SAMPLES_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "samples")
EXPECTED_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "expected")
GITLINT_USE_SH_LIB = os.environ.get("GITLINT_USE_SH_LIB", "[NOT SET]")

@classmethod
def setUpClass(cls):
# Run tests a temporary directory to shield them from any local git config
cls.original_working_dir = os.getcwd()
cls.working_dir = tempfile.mkdtemp()
os.chdir(cls.working_dir)

@classmethod
def tearDownClass(cls):
# Go back to original working dir and remove our temp working dir
os.chdir(cls.original_working_dir)
shutil.rmtree(cls.working_dir)

def setUp(self):
self.logcapture = LogCapture()
self.logcapture.setFormatter(logging.Formatter(LOG_FORMAT))
Expand Down
2 changes: 1 addition & 1 deletion gitlint-core/gitlint/tests/test_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def test_path_option(self):
option = PathOption("tëst-directory", ".", "Tëst Description", type="dir")
self.assertEqual(option.name, "tëst-directory")
self.assertEqual(option.description, "Tëst Description")
self.assertEqual(option.value, os.getcwd())
self.assertEqual(option.value, os.path.realpath("."))
self.assertEqual(option.type, "dir")

# re-set value
Expand Down