Engenere / BrazilFiscalReport

Python library for generating Brazilian auxiliary fiscal documents in PDF from XML documents.
GNU Lesser General Public License v3.0
27 stars 9 forks source link

Teste Unitários para cobertura de teste #6

Closed CristianoMafraJunior closed 8 months ago

CristianoMafraJunior commented 8 months ago

Adicionando Teste Unitários para aumento da cobertura dos teste

Teste : Teste criação de danfe com logo

def test_create_danfe_pdf_logo(self):
        current_dir = os.path.dirname(os.path.realpath(__file__))

        xml_file_path = os.path.join(current_dir, "data", "NFe_teste_cee.xml")
        logo_file_path = os.path.join(current_dir, "data", "Logo-Engenere.jpg")
        with open(xml_file_path, "r", encoding="utf8") as f:
            xmls = [f.read()]
        pdf = pdf_docs.Danfe(
            xmls=xmls, image=logo_file_path, cfg_layout="ICMS_ST", receipt_pos="top"
        )
        pdf.output("danfe_logo.pdf")

        self.assertTrue(os.path.isfile("danfe_logo.pdf"))

Teste : Teste de criação do danfe em paisagem

def test_create_danfe_pdf_paisagem(self):
        current_dir = os.path.dirname(os.path.realpath(__file__))
        xml_file_path = os.path.join(current_dir, "data", "NFe_teste_1.xml")

        with open(xml_file_path, "r", encoding="utf8") as f:
            xmls = [f.read()]
        xmls_paisagem = [
            xml.replace("<tpImp>1</tpImp>", "<tpImp>2</tpImp>") for xml in xmls
        ]
        pdf = pdf_docs.Danfe(
            xmls=xmls_paisagem, image=None, cfg_layout="ICMS_ST", receipt_pos="top"
        )

        pdf.recibo_l()
        pdf.output("danfe_paisagem.pdf")
        self.assertTrue(os.path.isfile("danfe_paisagem.pdf"))

Criando um danfe no formato paisagem

Teste : Verificar se esta trazendo os dados formato CODE128C

def test_code128_format(self):
        data = "123456789"
        expected_result = [
            xfpdf.CODE128C["StartC"],
            12,
            34,
            56,
            78,
            100,
            25,
            79,
            xfpdf.CODE128C["Stop"],
        ]
        result = self.xfpdf.code128_format(data)
        self.assertEqual(result, expected_result)

Teste: Criando um arquivo Cce

def test_create_cce_pdf(self):
        current_dir = os.path.dirname(os.path.realpath(__file__))

        xml_file_path = os.path.join(current_dir, "data", "xml_cce_1.xml")
        logo_file_path = os.path.join(current_dir, "data", "Logo-Engenere.jpg")

        # DaCCe
        emitente = {
            "nome": "COMPANY ME-EPP",
            "end": "AV TEST, 00",
            "bairro": "TEST",
            "cep": "00000-000",
            "cidade": "SÃO PAULO",
            "uf": "SP",
            "fone": "(11) 1234-5678",
        }
        with open(xml_file_path, "r", encoding="utf8") as f:
            xmls = [f.read()]

        pdf_cce = pdf_docs.DaCCe(xmls=xmls, emitente=emitente, image=logo_file_path)
        pdf_cce.output("cce.pdf")

        self.assertTrue(os.path.isfile("cce.pdf"))
codecov[bot] commented 8 months ago

Codecov Report

Attention: Patch coverage is 90.90909% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 89.52%. Comparing base (576c3bf) to head (af75d5e).

:exclamation: Current head af75d5e differs from pull request most recent head 7a54a14. Consider uploading reports for the commit 7a54a14 to get more accurate results

Files Patch % Lines
brazilfiscalreport/xfpdf.py 66.66% 0 Missing and 1 partial :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #6 +/- ## =========================================== + Coverage 48.45% 89.52% +41.06% =========================================== Files 2 2 Lines 974 974 Branches 77 77 =========================================== + Hits 472 872 +400 + Misses 472 66 -406 - Partials 30 36 +6 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.