Skip to content

Commit 0e85965

Browse files
committed
tests celia
1 parent c84b7da commit 0e85965

6 files changed

Lines changed: 115 additions & 0 deletions

File tree

test/img/0/python.png

8.23 KB
Loading

test/img/1/ejercicios.png

70.2 KB
Loading

test/test_buffdescribe.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
2+
import pandas as pd
3+
import pytest
4+
5+
from toolkit.data_processing import buffdescribe
6+
from toolkit.data_analysis import *
7+
from toolkit.machine_learning import *
8+
from toolkit.plot import *
9+
10+
@pytest.fixture
11+
12+
def test_df():
13+
return pd.DataFrame({'a': [1, 2, 3], 'b': ['x', 'y', 'z'], 'c': [4.5, 6.7, 8.9]})
14+
15+
def test_buffdescribe_columns(test_df):
16+
result = buffdescribe(test_df)
17+
assert result.index.tolist() == ['a', 'b', 'c']
18+
19+
def test_buffdescribe_data_type(test_df):
20+
result = buffdescribe(test_df)
21+
assert result['DATA_TYPE'].tolist() == ['int64', 'object', 'float64']
22+
23+
def test_buffdescribe_null_values(test_df):
24+
result = buffdescribe(test_df)
25+
assert result['MISSINGS (%)'].tolist() == [0.0, 0.0, 0.0]
26+
27+
def test_buffdescribe_non_null_values(test_df):
28+
result = buffdescribe(test_df)
29+
assert result['NOT_NULL'].tolist() == [3, 3, 3]
30+
31+
def test_buffdescribe_unique_values(test_df):
32+
result = buffdescribe(test_df)
33+
assert result['UNIQUE_VALUES'].tolist() == [3, 3, 3]
34+
35+
def test_buffdescribe_cardinality(test_df):
36+
result = buffdescribe(test_df)
37+
assert result['CARDIN (%)'].tolist() == [100.0, 100.0, 100.0]
38+
39+
def test_buffdescribe_descriptive_statistics(test_df):
40+
result = buffdescribe(test_df)
41+
assert result.columns.tolist() == ['DATA_TYPE', 'MISSINGS (%)', 'NOT_NULL', 'UNIQUE_VALUES', 'CARDIN (%)',
42+
'mean', 'median', 'std']
43+

test/test_clean_text.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import pytest
2+
import pandas as pd
3+
4+
from toolkit.data_processing import clean_text
5+
from toolkit.data_analysis import *
6+
from toolkit.machine_learning import *
7+
from toolkit.plot import *
8+
9+
@pytest.fixture
10+
11+
def test_data():
12+
# Crea un conjunto de datos de prueba para la función clean_text
13+
data = {'text': ['Este es un texto de prueba', 'Otro texto de prueba'],
14+
'target': [0, 1]}
15+
df = pd.DataFrame(data)
16+
return df
17+
18+
def test_clean_text(test_data):
19+
# Ejecuta la función clean_text con el conjunto de datos de prueba
20+
result = clean_text(test_data, 'text', 'spanish', 'target', 'test.csv')
21+
expected_columns = ['text', 'target']
22+
expected_result = pd.DataFrame({'text': ['text prueb', 'text prueb'], 'target': [0, 1]})
23+
24+
# Verifica que el resultado es igual al esperado
25+
assert result.columns.tolist() == expected_columns
26+
assert result.equals(expected_result)

test/test_load_imgs.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Importa la función a testear
2+
from toolkit.data_processing import load_imgs
3+
from toolkit.data_analysis import *
4+
from toolkit.machine_learning import *
5+
from toolkit.plot import *
6+
7+
import pandas as pd
8+
import numpy as np
9+
import os
10+
import pytest
11+
12+
13+
def test_load_imgs():
14+
# Define algunos parámetros de prueba
15+
path = os.getcwd() + '\\img'
16+
im_size = 64
17+
18+
# Llama a la función de prueba y obtiene los resultados
19+
df, X_train, y_train = load_imgs(path, im_size)
20+
21+
# Comprueba si los resultados devueltos son los esperados
22+
assert isinstance(df, pd.DataFrame)
23+
assert isinstance(X_train, np.ndarray)
24+
assert isinstance(y_train, np.ndarray)
25+
assert df.shape[0] == len(X_train) == len(y_train)
26+
assert set(df.columns) == set(['filename', 'category'])
27+
assert set(df['category'].unique()) == set(range(len(os.listdir(path))))
28+

test/test_plot_ngrams.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from toolkit.data_processing import *
2+
from toolkit.data_analysis import *
3+
from toolkit.machine_learning import *
4+
from toolkit.plot import plot_ngrams
5+
6+
import pandas as pd
7+
import numpy as np
8+
import plotly.graph_objs as go
9+
import pytest
10+
11+
12+
def test_plot_ngrams():
13+
df = pd.DataFrame({'target': [1, 0, 1], 'text': ['foo bar foo', 'baz qux', 'foo bar baz']})
14+
n_gram = 2
15+
fig = plot_ngrams(df, 'target', 'text', n_gram)
16+
assert isinstance(fig, go.Figure)
17+
assert len(fig['data']) == 2
18+

0 commit comments

Comments
 (0)