Skip to content

Commit

Permalink
delete folders after tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Maha Albashir authored and Maha Albashir committed Oct 8, 2023
1 parent eb1a405 commit 47003c4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
16 changes: 16 additions & 0 deletions test/test_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ def acro() -> ACRO:
return ACRO(suppress=True)


def clean_up(name):
"""Removes unwanted files or directory."""
if os.path.exists(name):
if os.path.isfile(name):
os.remove(name)
elif os.path.isdir(name):
shutil.rmtree(name)


def test_crosstab_without_suppression(data):
"""Crosstab threshold without automatic suppression."""
acro = ACRO(suppress=False)
Expand Down Expand Up @@ -849,3 +858,10 @@ def test_crosstab_with_manual_totals_with_suppression_with_two_aggfunc(
"We can not calculate the margins with a list of aggregation functions. "
"Please create a table for each aggregation function" in caplog.text
)


def test_cleanup():
"""Gets rid of files created during tests."""
names = ["test_outputs", "test_add_to_acro", "sdc_results", "RES_PYTEST"]
for name in names:
clean_up(name)
17 changes: 17 additions & 0 deletions test/test_stata_interface.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""This module contains unit tests for the stata interface."""

import os
import shutil

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -33,6 +34,15 @@ def data() -> pd.DataFrame:
return data


def clean_up(name):
"""Removes unwanted files or directory."""
if os.path.exists(name):
if os.path.isfile(name):
os.remove(name)
elif os.path.isdir(name):
shutil.rmtree(name)


def dummy_acrohandler(
data, command, varlist, exclusion, exp, weights, options
): # pylint:disable=too-many-arguments
Expand Down Expand Up @@ -736,3 +746,10 @@ def test_stata_unknown(data):
)
correct = "acro command not recognised: foo"
assert ret == correct, f"got:\n{ret}\nexpected:\n{correct}\n"


def test_cleanup():
"""Gets rid of files created during tests."""
names = ["test_outputs"]
for name in names:
clean_up(name)

0 comments on commit 47003c4

Please sign in to comment.