Skip to content

Commit

Permalink
tests: Add .gitignore to gunittest testreport folder if not present (#…
Browse files Browse the repository at this point in the history
…4092)

gunittest: Add .gitignore to testreport folder if not present

Co-authored-by: Edouard Choinière <[email protected]>
  • Loading branch information
echoix and echoix authored Jul 24, 2024
1 parent d7b13e0 commit 0306f93
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 3 additions & 2 deletions python/grass/gunittest/reporters.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import re
from collections.abc import Iterable

from .utils import ensure_dir
from .utils import add_gitignore_to_dir, ensure_dir
from .checkers import text_to_keyvalue


Expand Down Expand Up @@ -330,9 +330,10 @@ def __init__(self, reporters, forgiving=False):

def start(self, results_dir):
# TODO: no directory cleaning (self.clean_before)? now cleaned by caller
# TODO: perhaps only those whoe need it should do it (even multiple times)
# TODO: perhaps only those who need it should do it (even multiple times)
# and there is also the delete problem
ensure_dir(os.path.abspath(results_dir))
add_gitignore_to_dir(os.path.abspath(results_dir))
for reporter in self.reporters:
try:
reporter.start(results_dir)
Expand Down
7 changes: 7 additions & 0 deletions python/grass/gunittest/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import errno
import os
from pathlib import Path
import shutil
import sys

Expand All @@ -21,6 +22,12 @@ def ensure_dir(directory):
os.makedirs(directory)


def add_gitignore_to_dir(directory):
gitignore_path = Path(directory) / ".gitignore"
if not Path(gitignore_path).exists():
Path(gitignore_path).write_text("*")


def silent_rmtree(filename):
"""Remove the file but do nothing if file does not exist."""
try:
Expand Down

0 comments on commit 0306f93

Please sign in to comment.