Skip to content

Commit

Permalink
Merge pull request #165 from datosgobar/159-bugfix-xlsx-writer
Browse files Browse the repository at this point in the history
159 bugfix xlsx writer
  • Loading branch information
poligarcia committed Jun 11, 2018
2 parents b422b53 + cfed1d6 commit 5947bf3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pydatajson/writers.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ def write_xlsx_catalog(catalog, path, xlsx_fields=None):

catalog_dict["catalog"] = [
_tabulate_nested_dict(catalog.get_catalog_metadata(
exclude_meta_fields=["superThemeTaxonomy", "themeTaxonomy"]),
exclude_meta_fields=["themeTaxonomy"]),
"catalog")
]
catalog_dict["dataset"] = _generate_dataset_table(catalog)
Expand Down
27 changes: 27 additions & 0 deletions tests/test_readers_and_writers.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,33 @@ def test_write_json_catalog_is_write_json(self, mock_write_json):

pydatajson.writers.write_json.assert_called_once_with(obj, path)

def test_read_write_both_formats_yields_the_same(self):
for suffix in ['xlsx', 'json']:
catalog = pydatajson.core.DataJson(
os.path.join(self.SAMPLES_DIR,
"catalogo_justicia." + suffix))
catalog.to_json(os.path.join(self.TEMP_DIR,
"saved_catalog.json"))
catalog.to_xlsx(os.path.join(self.TEMP_DIR,
"saved_catalog.xlsx"))
catalog_json = pydatajson.core.DataJson(
os.path.join(self.TEMP_DIR,
"saved_catalog.xlsx"))
catalog_xlsx = pydatajson.core.DataJson(
os.path.join(self.TEMP_DIR,
"saved_catalog.xlsx"))
self.assertEqual(catalog_json, catalog_xlsx)

# la llamada to_xlsx() genera los indices en el catalogo original
# aplicarla a los catalogos generados debería dejarlos igual al original
catalog_xlsx.to_xlsx(os.path.join(self.TEMP_DIR,
"otro.xlsx"))
catalog_json.to_xlsx(os.path.join(self.TEMP_DIR,
"otro.xlsx"))

self.assertEqual(catalog_json, catalog)
self.assertEqual(catalog_xlsx, catalog)


if __name__ == '__main__':
nose.run(defaultTest=__name__)

0 comments on commit 5947bf3

Please sign in to comment.