Skip to content

Commit

Permalink
Remove super()
Browse files Browse the repository at this point in the history
  • Loading branch information
BlankCheng committed May 18, 2024
1 parent 7a22a3c commit 1403837
Show file tree
Hide file tree
Showing 15 changed files with 49 additions and 60 deletions.
2 changes: 1 addition & 1 deletion data/raw/f_245_indraneil.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def test_case_2(self):
self.assertEqual(ax.get_ylabel(), 'Count', "Y-axis label is incorrect.")
self.assertEqual(sum([p.get_height() for p in ax.patches]), len(obj_list), "Histogram data points do not match input list size.")
# Check axis data
self.assertAlmostEqual(ax.get_xlim()[0], -2.57, delta=0.1, msg="X-axis lower limit is incorrect.")
self.assertAlmostEqual(ax.get_xlim()[0], -3.933336166652307, delta=0.1, msg="X-axis lower limit is incorrect.")

def test_case_3(self):
# Input 3: List of objects with fixed value
Expand Down
5 changes: 2 additions & 3 deletions data/raw/f_271_indraneil.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,10 @@ def setup_test_directory():
class TestCases(unittest.TestCase):
def setUp(self):
setup_test_directory()
super().setUp()

def tearDown(self):
shutil.rmtree(TEST_DIR_PATH)
super().tearDown()
if os.path.exists(TEST_DIR_PATH):
shutil.rmtree(TEST_DIR_PATH)

def test_case_1(self):
# Test with 5 JSON files containing various keys
Expand Down
9 changes: 4 additions & 5 deletions data/raw/f_288_indraneil.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,11 @@ def setUp(self) -> None:
self.temp_dir = f"{self.base_tmp_dir}/test"
if not os.path.exists(self.temp_dir):
os.mkdir(self.temp_dir)
return super().setUp()


def tearDown(self) -> None:
shutil.rmtree(self.base_tmp_dir)
return super().tearDown()
if os.path.exists(self.base_tmp_dir):
shutil.rmtree(self.base_tmp_dir)

def test_case_1(self):
# Test with the first sample directory
input_text = {
Expand Down
2 changes: 0 additions & 2 deletions data/raw/f_294_indraneil.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,10 @@ def setUp(self):
else open(os.path.join(self.test_directory, filename), 'x')
) as file:
file.write(content)
return super().setUp()

def tearDown(self):
if os.path.exists(self.test_directory):
shutil.rmtree(self.test_directory)
return super().tearDown()

def test_case_1(self):
matched_files = f_294('.*hello.*', self.test_directory, self.extensions)
Expand Down
4 changes: 1 addition & 3 deletions data/raw/f_298_indraneil.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,10 @@ def setUp(self):
else open(path, "x")
) as file:
file.write(content)
super().setUp()

def tearDown(self):
shutil.rmtree(f"{self.base_dir}")
super().tearDown()


def test_case_1(self):
# Testing script1.py that should exit with code 0
return_code = f_298(self.script_paths[0])
Expand Down
9 changes: 4 additions & 5 deletions data/raw/f_300_indraneil.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,12 @@ def setUp(self):
file.write(content)
file_paths.append(file_path)

return super().setUp()


def tearDown(self):
# Reset the test folders after each test
shutil.rmtree(self.base_tmp_dir, ignore_errors=True)
return super().tearDown()
if os.path.exists(self.base_tmp_dir):
shutil.rmtree(self.base_tmp_dir, ignore_errors=True)

def test_case_1(self):
"""Test basic functionality."""
# Create some sample files in the source folder
Expand Down
1 change: 0 additions & 1 deletion data/raw/f_304_indraneil.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ class TestCases(unittest.TestCase):
def tearDown(self) -> None:
if os.path.exists(self.file_name):
os.remove(self.file_name)
return super().tearDown()

def test_case_1(self):
# Test with n = 3
Expand Down
5 changes: 2 additions & 3 deletions data/raw/f_306_indraneil.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,10 @@ def setUp(self):

for dir_name in self.dest_dirs.keys():
os.makedirs(dir_name, exist_ok=True)
return super().setUp()

def tearDown(self):
shutil.rmtree(self.base_test_dir)
return super().tearDown()
if os.path.exists(self.base_test_dir):
shutil.rmtree(self.base_test_dir)

def test_case_1(self):
moved_file = f_306(
Expand Down
5 changes: 2 additions & 3 deletions data/raw/f_307_indraneil.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,10 @@ def setUp(self):

with open(os.path.join(self.test_directory, "file2.json"), "w") as file:
json.dump(self.json_data2, file)
super(TestCases, self).setUp()

def tearDown(self):
shutil.rmtree(self.test_directory)
super(TestCases, self).tearDown()
if os.path.exists(self.test_directory):
shutil.rmtree(self.test_directory)

def test_case_1(self):
# Test with the sample directory created
Expand Down
6 changes: 2 additions & 4 deletions data/raw/f_308_indraneil.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,9 @@ def setUp(self):
doc.add_paragraph(paragraph)
doc.save(self.test_directory + file_name)

super(TestCases, self).setUp()

def tearDown(self):
shutil.rmtree(self.test_directory)
super(TestCases, self).tearDown()
if os.path.exists(self.test_directory):
shutil.rmtree(self.test_directory)

def read_docx_content(self, file_path):
doc = Document(file_path)
Expand Down
45 changes: 25 additions & 20 deletions data/raw/f_309_indraneil.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ def f_309(directory_path='./xlsx_files/'):
for row in workbook[sheet].iter_rows():
for cell in row:
if isinstance(cell.value, str):
cell.value = re.sub(r'(?<=(^|[^\\])(\\\\)*)"', r'\"', cell.value)
cell.value = re.sub(r'(?<=(^|[^\\])(\\\\)*)"', r'\"',
cell.value)

workbook.save(xlsx_file)
processed_files += 1
Expand Down Expand Up @@ -104,54 +105,58 @@ def setUp(self):
sheet = workbook.create_sheet(title=sheet_name)
for row in rows:
sheet.append(row)
workbook.save(filename=os.path.join(self.test_directory, file_info["filename"]))

super(TestCases, self).setUp()
workbook.save(
filename=os.path.join(self.test_directory, file_info["filename"]))

def tearDown(self):
# Remove the test directory
shutil.rmtree(self.test_directory)
super(TestCases, self).tearDown()

if os.path.exists(self.test_directory):
shutil.rmtree(self.test_directory)

def test_case_1(self):
# Process the mock Excel files
processed_files_count = f_309(directory_path=self.test_directory)

# Check the number of processed files
self.assertEqual(processed_files_count, 3)

# Check the content of file1.xlsx
workbook = load_workbook(filename=os.path.join(self.test_directory, "file1.xlsx"))
workbook = load_workbook(
filename=os.path.join(self.test_directory, "file1.xlsx"))
sheet = workbook.active
self.assertEqual(sheet.cell(row=1, column=3).value, 'This is a \\"test\\" string.')
self.assertEqual(sheet.cell(row=1, column=3).value,
'This is a \\"test\\" string.')
self.assertEqual(sheet.cell(row=2, column=2).value, 'Row with \\"quotes\\"')
self.assertEqual(sheet.cell(row=2, column=3).value, 'And \\"more\\" quotes.')

def test_case_2(self):
# Check the content of file2.xlsx
workbook = load_workbook(filename=os.path.join(self.test_directory, "file2.xlsx"))
workbook = load_workbook(
filename=os.path.join(self.test_directory, "file2.xlsx"))
sheet1 = workbook["Sheet1"]
self.assertEqual(sheet1.cell(row=1, column=1).value, 'Just a')

sheet2 = workbook["Sheet2"]
self.assertEqual(sheet2.cell(row=1, column=2).value, "Another \"quoted\" string.")

self.assertEqual(sheet2.cell(row=1, column=2).value,
"Another \"quoted\" string.")

def test_case_3(self):
# Check the content of file3.xlsx
workbook = load_workbook(filename=os.path.join(self.test_directory, "file3.xlsx"))
workbook = load_workbook(
filename=os.path.join(self.test_directory, "file3.xlsx"))
sheet = workbook.active
self.assertEqual(sheet.cell(row=1, column=1).value, 'A simple')

def test_case_4(self):
# Test with a directory that doesn't exist
with self.assertRaises(FileNotFoundError):
f_309(directory_path="/invalid/directory/")

def test_case_5(self):
# Test with a directory that contains no .xlsx files
os.makedirs(f"{self.test_directory}/empty_directory/", exist_ok=True)
processed_files_count = f_309(directory_path=f"{self.test_directory}/empty_directory/")
processed_files_count = f_309(
directory_path=f"{self.test_directory}/empty_directory/")
self.assertEqual(processed_files_count, 0)


Expand Down
1 change: 0 additions & 1 deletion data/raw/f_312_indraneil.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ def f_312(text, n, top_k):
class TestCases(unittest.TestCase):
def tearDown(self) -> None:
plt.close('all')
return super().tearDown()

def test_case_1(self):
# Test with a simple text, bigram (n=2) and top 2 n-grams
Expand Down
5 changes: 2 additions & 3 deletions data/raw/f_316_indraneil.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,10 @@ def setUp(self):
f.write("Dummy content for testing.")
if os.path.exists(os.path.join(self.test_directory, "Interesting Files")):
shutil.rmtree(os.path.join(self.test_directory, "Interesting Files"))
super(TestCases, self).setUp()

def tearDown(self):
shutil.rmtree(self.test_directory)
super(TestCases, self).tearDown()
if os.path.exists(self.test_directory):
shutil.rmtree(self.test_directory)

def test_caae_1(self):
"""Test if only files with 'like' or 'what' in their names are moved."""
Expand Down
5 changes: 2 additions & 3 deletions data/raw/f_321_indraneil.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,10 @@ def write_json_file(file_name, data):
write_json_file('invalid.json', invalid_json_data)
write_json_file('empty.json', empty_json_data)
write_json_file('non_dict_list.json', non_dict_list_json_data)
super(TestCases, self).setUp()

def tearDown(self):
shutil.rmtree(self.test_data_folder)
super(TestCases, self).tearDown()
if os.path.exists(self.test_data_folder):
shutil.rmtree(self.test_data_folder)

def test_case_1(self):
file_path = os.path.join(self.test_data_folder, 'valid.json')
Expand Down
5 changes: 2 additions & 3 deletions data/raw/f_323_indraneil.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,10 @@ def setUp(self):
# Empty directory for testing
empty_dir = os.path.join(self.test_dir, 'empty_dir')
os.makedirs(empty_dir, exist_ok=True)
super(TestCases, self).setUp()

def tearDown(self):
shutil.rmtree(self.test_dir)
super(TestCases, self).tearDown()
if os.path.exists(self.test_dir):
shutil.rmtree(self.test_dir)

def test_with_target_string(self):
"""Test with files containing the target string."""
Expand Down

0 comments on commit 1403837

Please sign in to comment.