Repository: fga-eps-mds/2022-2-ez-docs (language: python)

Issue:
Testes
# Descrição

## Testes
- Biblioteca Pytest - [pytest: helps you write better programs — pytest documentation](https://docs.pytest.org/en/7.2.x/)
- Testes unitários
- 80% de cobertura

- [x] Pesquisa sobre a biblioteca Pytests
- [x] Realização dos testes
Testes
# Descrição

## Testes
- Biblioteca Pytest - [pytest: helps you write better programs — pytest documentation](https://docs.pytest.org/en/7.2.x/)
- Testes unitários
- 80% de cobertura

- [x] Pesquisa sobre a biblioteca Pytests
- [x] Realização dos testes
Testes
# Descrição

## Testes
- Biblioteca Pytest - [pytest: helps you write better programs — pytest documentation](https://docs.pytest.org/en/7.2.x/)
- Testes unitários
- 80% de cobertura

- [x] Pesquisa sobre a biblioteca Pytests
- [x] Realização dos testes
Testes
# Descrição

## Testes
- Biblioteca Pytest - [pytest: helps you write better programs — pytest documentation](https://docs.pytest.org/en/7.2.x/)
- Testes unitários
- 80% de cobertura

- [x] Pesquisa sobre a biblioteca Pytests
- [x] Realização dos testes
Testes
# Descrição

## Testes
- Biblioteca Pytest - [pytest: helps you write better programs — pytest documentation](https://docs.pytest.org/en/7.2.x/)
- Testes unitários
- 80% de cobertura

- [x] Pesquisa sobre a biblioteca Pytests
- [x] Realização dos testes


Discussion / hints:

Fix patch:
diff --git a/src/ez_docs/__pycache__/main.cpython-311.pyc b/src/ez_docs/__pycache__/main.cpython-311.pyc
new file mode 100644
index 0000000..c478f1e
Binary files /dev/null and b/src/ez_docs/__pycache__/main.cpython-311.pyc differ


Test patch:
diff --git a/test/__pycache__/test_dataCleaning.cpython-311-pytest-7.2.0.pyc b/test/__pycache__/test_dataCleaning.cpython-311-pytest-7.2.0.pyc
new file mode 100644
index 0000000..dc78458
Binary files /dev/null and b/test/__pycache__/test_dataCleaning.cpython-311-pytest-7.2.0.pyc differ
diff --git a/test/__pycache__/test_docGeneration.cpython-311-pytest-7.2.0.pyc b/test/__pycache__/test_docGeneration.cpython-311-pytest-7.2.0.pyc
new file mode 100644
index 0000000..a37cb0a
Binary files /dev/null and b/test/__pycache__/test_docGeneration.cpython-311-pytest-7.2.0.pyc differ
diff --git a/test/__pycache__/test_doc_generation.cpython-311-pytest-7.2.0.pyc b/test/__pycache__/test_doc_generation.cpython-311-pytest-7.2.0.pyc
new file mode 100644
index 0000000..18f4404
Binary files /dev/null and b/test/__pycache__/test_doc_generation.cpython-311-pytest-7.2.0.pyc differ
diff --git a/test/__pycache__/test_main.cpython-311-pytest-7.2.0.pyc b/test/__pycache__/test_main.cpython-311-pytest-7.2.0.pyc
new file mode 100644
index 0000000..c3fb1fc
Binary files /dev/null and b/test/__pycache__/test_main.cpython-311-pytest-7.2.0.pyc differ
diff --git a/test/__pycache__/test_usable.cpython-311-pytest-7.2.0.pyc b/test/__pycache__/test_usable.cpython-311-pytest-7.2.0.pyc
new file mode 100644
index 0000000..127754a
Binary files /dev/null and b/test/__pycache__/test_usable.cpython-311-pytest-7.2.0.pyc differ
diff --git a/test/example.csv b/test/example.csv
new file mode 100644
index 0000000..cd725b9
--- /dev/null
+++ b/test/example.csv
@@ -0,0 +1,6 @@
+nome,idade
+Bruno, 18
+Miguel, 18
+Gobbi, 18
+Igor, 18
+Igor, 18
\ No newline at end of file
diff --git a/test/template.md b/test/template.md
new file mode 100644
index 0000000..48f212d
--- /dev/null
+++ b/test/template.md
@@ -0,0 +1,3 @@
+# <<nome>>
+
+Membro do squad 7 de MDS. Idade = <<idade>>
\ No newline at end of file
diff --git a/test/test_dataCleaning.py b/test/test_dataCleaning.py
new file mode 100644
index 0000000..df376d3
--- /dev/null
+++ b/test/test_dataCleaning.py
@@ -0,0 +1,22 @@
+from ez_docs.modules.data_cleaning import filter_data
+
+final_data = [
+    {'nome': 'Bruno', 'idade': '18'},
+    {'nome': 'Miguel', 'idade': '18'},
+    {'nome': 'Gobbi', 'idade': '18'},
+    {'nome': 'Igor', 'idade': '18'},
+]
+
+final_data2 = [
+    {'nome': 'Bruno', 'idade': '18'},
+    {'nome': 'Miguel', 'idade': '18'},
+    {'nome': 'Gobbi', 'idade': '18'},
+    {'nome': 'Igor', 'idade': '18'},
+    {'nome': 'Igor', 'idade': '18'},
+]
+
+def test_data_cleaning():
+    assert filter_data("test/example.csv") == final_data
+
+def test_data_cleaning_error():
+    assert filter_data("test/example.csv") != final_data2
\ No newline at end of file
diff --git a/test/test_docGeneration.py b/test/test_docGeneration.py
new file mode 100644
index 0000000..15cef8f
--- /dev/null
+++ b/test/test_docGeneration.py
@@ -0,0 +1,24 @@
+from ez_docs.modules.doc_generation import *
+
+key_value = {
+    "NOME": "Wallace",
+    "MATRICULA": "20990088"
+}
+
+def test_loc_sub():
+    assert loc_sub("Ola <<Chave>>", "Chave", "Mundo")  == "Ola Mundo"
+
+def test_loc_sub_error():
+    assert loc_sub("Ola <<Chave>>", "Chave", "Mundo")  != "Ola Mudo"
+
+def test_slugify():
+    assert slugify("bruno#o:brabo. mago") == "brunoobrabo-mago"
+
+def test_slugify_error():
+    assert slugify("bruno#o:brabo. mago") != "bruno#o:brabo. mago"
+
+def test_recognize_file_name():
+    assert recognize_file_name(key_value, "NOME_MATRICULA") == "wallace_20990088"
+
+def test_recognize_file_name_error():
+    assert recognize_file_name(key_value, "NOME_MATRICULA") != "Wallace_20990088"
\ No newline at end of file
diff --git a/test/test_main.py b/test/test_main.py
new file mode 100644
index 0000000..3fd44d0
--- /dev/null
+++ b/test/test_main.py
@@ -0,0 +1,52 @@
+from ez_docs.main import *
+import shutil
+
+# "template.md example.csv name_idade"
+
+example = {
+    "template_directory": "test/template.md",
+    "base_directory": "test/example.csv",
+    "file_name_pattern": "nome_idade",
+    "flag": 1
+}
+
+def test_mk_docs():
+    mk_docs(example)
+    x = len(os.listdir('output'))
+    shutil.rmtree('output')
+    assert x == 4
+
+def test_mk_docs_error():
+    mk_docs(example)
+    x = len(os.listdir('output'))
+    shutil.rmtree('output')
+    assert x != 3
+
+def test_main(monkeypatch):
+    def mock_parse_args(self):
+        return argparse.Namespace(
+            flag = 1,
+            template_directory='template.md',
+            base_directory='dados.csv', file_name_pattern='NOME_MATRICULA',
+            _get_kwargs=lambda: {'flag': 1, 'template_directory': 'test/template.md', 'base_directory': 'test/example.csv', 'file_name_pattern': 'nome_idade'}
+        )
+    monkeypatch.setattr(argparse.ArgumentParser, 'parse_args', mock_parse_args)
+    main()
+    x = len(os.listdir('output'))
+    shutil.rmtree('output')
+    assert x == 4
+
+def test_main_error(monkeypatch):
+    def mock_parse_args(self):
+        return argparse.Namespace(
+            flag = 1,
+            template_directory='template.md',
+            base_directory='dados.csv', file_name_pattern='NOME_MATRICULA',
+            _get_kwargs=lambda: {'flag': 1, 'template_directory': 'test/template.md', 'base_directory': 'test/example.csv', 'file_name_pattern': 'nome_idade'}
+        )
+    monkeypatch.setattr(argparse.ArgumentParser, 'parse_args', mock_parse_args)
+    main()
+    x = len(os.listdir('output'))
+    shutil.rmtree('output')
+    assert x != 3
+
diff --git a/test/test_usable.py b/test/test_usable.py
new file mode 100644
index 0000000..840536d
--- /dev/null
+++ b/test/test_usable.py
@@ -0,0 +1,13 @@
+from ez_docs.modules.usable import*
+
+def test_progress_bar(capsys):
+    progress_bar(4, 10, "#", 10)
+    out, err = capsys.readouterr()
+    out = out[len("\x1b[93m(1/10)\x1b[0m  10.00% [\x1b[96m") :-len("\x1b[0m]\n")]
+    assert out == "####"
+
+def test_progress_bar_error(capsys):
+    progress_bar(8, 10, "#", 10)
+    out, err = capsys.readouterr()
+    out = out[len("\x1b[93m(1/10)\x1b[0m  10.00% [\x1b[96m") :-len("\x1b[0m]\n")]
+    assert out != "#####"
\ No newline at end of file