Spaces:
Sleeping
Sleeping
Download tests/test_conservation_notes.py from gui-sparim/teste_docs: direct link, hf CLI and curl.
- Browser
- Download file 4.39 kB
-
https://huggingface.co/spaces/gui-sparim/teste_docs/resolve/main/tests/test_conservation_notes.py
- Command line
-
hf download hf://spaces/gui-sparim/teste_docs/tests/test_conservation_notes.py
-
curl -L -o test_conservation_notes.py https://huggingface.co/spaces/gui-sparim/teste_docs/resolve/main/tests/test_conservation_notes.py
4.39 kB
| import copy | |
| import unittest | |
| from docx import Document | |
| from docx.opc.constants import RELATIONSHIP_TYPE as RT | |
| from docx.oxml import parse_xml | |
| from docx.oxml.ns import qn | |
| from document.evolutivo import construction_characteristics, construction_groups | |
| from test_evo_adjustments import body | |
| from test_evolutivo_documento import fixture, resolved, all_text | |
| def notes(doc): | |
| root = parse_xml(doc.part.part_related_by(RT.FOOTNOTES).blob) | |
| return [''.join(n.itertext(qn('w:t'))) for n in root if int(n.get(qn('w:id'))) > 0] | |
| class ConservationNotesTests(unittest.TestCase): | |
| def data(self): | |
| data = fixture((2021, 2022)) | |
| for year in data['anos']: | |
| year['construcao']['avaliacao']['referenciasCalculo'] = { | |
| 'vidaUtilTipos': [{'tipo': 'GALPOES (DEPOSITOS)', 'vidaUtil': 70}], | |
| 'estadosConservacao': [{'estado': 'C - regular', 'coeficiente': .0252, | |
| 'descricao': 'Descrição histórica da classe regular.'}]} | |
| year['construcao']['construcoes'][0].update(estadoConservacao='C - regular', coefHeidecke=.0317) | |
| return data | |
| def test_codes_and_saved_coefficients_in_tables_descriptions_only_in_notes(self): | |
| imported = resolved(self.data()) | |
| before = copy.deepcopy(imported) | |
| doc = body(imported) | |
| characteristics = next(t for t in doc.tables if t.cell(0, 1).text == 'Tipo / ano') | |
| self.assertEqual([c.text for c in characteristics.rows[0].cells][-2:], ['Estado de conservação', 'H']) | |
| self.assertEqual([c.text for c in characteristics.rows[1].cells][-2:], ['C', '0,0317']) | |
| calculation = next(t for t in doc.tables if any(r.cells[0].text == 'Coeficiente H' for r in t.rows)) | |
| for label, expected in [('Estado de conservação', 'C'), ('Coeficiente H', '0,0317')]: | |
| row = next(r for r in calculation.rows if r.cells[0].text == label) | |
| self.assertEqual([c.text for c in row.cells[1:]], [expected, expected]) | |
| self.assertNotIn('Descrição histórica', all_text(doc)) | |
| self.assertNotIn('Referência de vida útil para', all_text(doc)) | |
| self.assertNotIn('Ajuste manual de vida consumida', all_text(doc)) | |
| footnotes = notes(doc) | |
| self.assertEqual(sum('Descrição histórica da classe regular.' in text for text in footnotes), 1) | |
| self.assertTrue(any('70 anos' in text and 'R é o valor residual' in text for text in footnotes)) | |
| self.assertTrue(any('IPTU 2022; IPTU 2023' in text and 'padrão 50,00%; adotado 40,00%' in text for text in footnotes)) | |
| self.assertNotIn('SEGREDO INTERNO', ' '.join(footnotes)) | |
| self.assertEqual(imported, before) | |
| def test_shared_class_is_explained_once_and_historical_changes_keep_their_scope(self): | |
| data = self.data() | |
| for year in data['anos']: | |
| second = copy.deepcopy(year['construcao']['construcoes'][0]) | |
| second.update(id='segundo', seq=2, nome='Galpão B') | |
| year['construcao']['construcoes'].append(second) | |
| data['anos'][1]['construcao']['avaliacao']['referenciasCalculo']['estadosConservacao'][0]['descricao'] = 'Caracterização revista no segundo exercício.' | |
| doc = Document() | |
| construction_characteristics(doc, construction_groups(resolved(data)['avaliacoes'])) | |
| self.assertEqual(len(doc.tables[0].rows), 5) | |
| for index in (1, 3): | |
| self.assertIn('IPTU 2022', doc.tables[0].cell(index, 0).text) | |
| self.assertIn('IPTU 2023', doc.tables[0].cell(index + 1, 0).text) | |
| self.assertEqual(sum('Descrição histórica' in text for text in notes(doc)), 1) | |
| self.assertEqual(sum('Caracterização revista' in text for text in notes(doc)), 1) | |
| def test_unknown_state_keeps_original_label_without_borrowing_catalog_description(self): | |
| data = self.data() | |
| for year in data['anos']: | |
| year['construcao']['construcoes'][0]['estadoConservacao'] = 'C - classificação especial' | |
| doc = Document() | |
| construction_characteristics(doc, construction_groups(resolved(data)['avaliacoes'])) | |
| self.assertIn('C - classificação especial', ' '.join(notes(doc))) | |
| self.assertNotIn('Descrição histórica', ' '.join(notes(doc))) | |
| self.assertIn('não foi preservada', ' '.join(notes(doc))) | |
| if __name__ == '__main__': | |
| unittest.main() | |