Skip to content

Commit

Permalink
removed unittest dependency
Browse files Browse the repository at this point in the history
Signed-off-by: SONIABHISHEK121 <[email protected]>
  • Loading branch information
ABHISHEKSONI121 committed Aug 15, 2024
1 parent df3d56e commit 1c141f1
Showing 1 changed file with 22 additions and 26 deletions.
48 changes: 22 additions & 26 deletions tests/test_formato_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import os
import sys
import unittest
import csv
import pytest
import tempfile
Expand All @@ -35,7 +34,7 @@


@pytest.mark.dontusefix
class TestLeerFunction(unittest.TestCase):
class TestLeerFunction:
def test_leer_csv_file(self):
"""
Test that the leer function can read a valid CSV file correctly.
Expand Down Expand Up @@ -121,7 +120,7 @@ def test_leer_csv_file(self):
]
]
result = leer("datos/facturas.csv", delimiter=";")
self.assertEqual(result, expected_data)
assert result == expected_data

def test_leer_csv_custom_delimiter(self):
"""
Expand All @@ -140,7 +139,7 @@ def test_leer_csv_custom_delimiter(self):

with patch("builtins.open", return_value=StringIO(sample_csv_data)):
result = leer("data/sample.csv", delimiter="|")
self.assertEqual(result, expected_data)
assert result == expected_data

def test_leer_csv_with_header(self):
"""
Expand All @@ -159,7 +158,7 @@ def test_leer_csv_with_header(self):

with patch("builtins.open", return_value=StringIO(sample_csv_data)):
result = leer("data/sample.csv")
self.assertEqual(result, expected_data)
assert result == expected_data

def test_leer_csv_without_header(self):
"""
Expand All @@ -177,7 +176,7 @@ def test_leer_csv_without_header(self):

with patch("builtins.open", return_value=StringIO(sample_csv_data)):
result = leer("data/sample.csv", header=False)
self.assertEqual(result, expected_data)
assert result == expected_data

def test_leer_csv_with_whitespace(self):
"""
Expand All @@ -196,7 +195,7 @@ def test_leer_csv_with_whitespace(self):

with patch("builtins.open", return_value=StringIO(sample_csv_data)):
result = leer("data/sample.csv")
self.assertEqual(result, expected_data)
assert result == expected_data

def test_leer_csv_with_non_string_values(self):
"""
Expand All @@ -215,7 +214,7 @@ def test_leer_csv_with_non_string_values(self):

with patch("builtins.open", return_value=StringIO(sample_csv_data)):
result = leer("data/sample.csv")
self.assertEqual(result, expected_data)
assert result == expected_data

def test_leer_csv_different_dialect(self):
"""
Expand All @@ -234,7 +233,7 @@ def test_leer_csv_different_dialect(self):

with patch("builtins.open", return_value=StringIO(sample_csv_data)):
result = leer("data/sample.csv", delimiter=";")
self.assertEqual(result, expected_data)
assert result == expected_data

def test_leer_csv_empty_file(self):
"""
Expand All @@ -245,7 +244,7 @@ def test_leer_csv_empty_file(self):

with patch("builtins.open", return_value=StringIO(sample_csv_data)):
result = leer("data/sample.csv")
self.assertEqual(result, expected_data)
assert result == expected_data

def test_leer_xlsx_file_with_header(self):
"""
Expand Down Expand Up @@ -273,7 +272,7 @@ def test_leer_xlsx_file_with_header(self):
workbook.save(temp_file.name)

result = leer(temp_file.name)
self.assertEqual(result, expected_data)
assert result == expected_data

# Clean up the temporary file
os.unlink(temp_file.name)
Expand Down Expand Up @@ -301,14 +300,14 @@ def test_leer_xlsx_file_without_header(self):
workbook.save(temp_file.name)

result = leer(temp_file.name, header=False)
self.assertEqual(result, expected_data)
assert result == expected_data

# Clean up the temporary file
os.unlink(temp_file.name)


@pytest.mark.dontusefix
class TestAplanarFunction(unittest.TestCase):
class TestAplanarFunction:
def test_aplanar_single_record(self):
"""
Test that the aplanar function correctly flattens a single record.
Expand Down Expand Up @@ -536,7 +535,7 @@ def test_aplanar_single_record(self):
]

result = aplanar([reg])
self.assertEqual(result, expected_data)
assert result == expected_data

def test_aplanar_multiple_records(self):
"""
Expand Down Expand Up @@ -887,11 +886,11 @@ def test_aplanar_multiple_records(self):
]

result = aplanar(regs)
self.assertEqual(result, expected_data)
assert result == expected_data


@pytest.mark.dontusefix
class TestDesplanarFunction(unittest.TestCase):
class TestDesplanarFunction:
def test_desaplanar_single_record(self):
"""
Test that the desaplanar function correctly converts
Expand Down Expand Up @@ -1096,7 +1095,7 @@ def test_desaplanar_single_record(self):
]

result = desaplanar(filas)
self.assertEqual(result, expected_data)
assert result == expected_data

def test_desaplanar_multiple_records(self):
"""
Expand Down Expand Up @@ -1436,11 +1435,11 @@ def test_desaplanar_multiple_records(self):
]

result = desaplanar(filas)
self.assertEqual(result, expected_data)
assert result == expected_data


@pytest.mark.dontusefix
class TestEscribirFunction(unittest.TestCase):
class TestEscribirFunction:
def test_escribir_facturas_csv(self):
"""
Test that the escribir function can write data
Expand All @@ -1456,14 +1455,14 @@ def test_escribir_facturas_csv(self):
escribir(filas, filename)

# Check if the file was created
self.assertTrue(os.path.exists(filename))
assert os.path.isfile(filename)

# Read the contents of the output file and compare
# with the original data
with open(filename, "r", newline="") as file:
csv_reader = csv.reader(file, delimiter=";")
result = [row for row in csv_reader]
self.assertEqual(result, filas)
assert result == filas

# Clean up the test file
os.remove(filename)
Expand All @@ -1483,7 +1482,7 @@ def test_escribir_facturas_xlsx(self):
escribir(filas, filename)

# Check if the file was created
self.assertTrue(os.path.exists(filename))
assert os.path.isfile(filename)

# Read the contents of the XLSX file and compare with the original data
workbook = load_workbook(filename)
Expand All @@ -1493,11 +1492,8 @@ def test_escribir_facturas_xlsx(self):
# Convert None values to empty strings
row = ["" if cell is None else str(cell) for cell in row]
result.append(row)
self.assertEqual(result, filas)
assert result == filas

# Clean up the test file
os.remove(filename)


if __name__ == "__main__":
unittest.main()

0 comments on commit 1c141f1

Please sign in to comment.