Skip to content

Commit b4b4cc2

Browse files
author
Kyle Allan
authored
add functions to write_catalog (#101)
1 parent 008fa38 commit b4b4cc2

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

singer/catalog.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@
1010
LOGGER = get_logger()
1111

1212

13+
def write_catalog(catalog):
14+
# If the catalog has no streams, log a warning
15+
if not catalog.streams:
16+
LOGGER.warning("Catalog being written with no streams.")
17+
18+
json.dump(catalog.to_dict(), sys.stdout, indent=2)
19+
1320
# pylint: disable=too-many-instance-attributes
1421
class CatalogEntry():
1522

tests/test_catalog.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
import unittest
22

33
from singer.schema import Schema
4-
from singer.catalog import Catalog, CatalogEntry
4+
from singer.catalog import Catalog, CatalogEntry, write_catalog
5+
6+
class TestWriteCatalog(unittest.TestCase):
7+
def test_write_empty_catalog(self):
8+
catalog = Catalog([])
9+
write_catalog(catalog)
10+
11+
def test_write_catalog_with_streams(self):
12+
catalog = Catalog([CatalogEntry(tap_stream_id='a',schema=Schema(),metadata=[])])
13+
write_catalog(catalog)
514

615
class TestGetSelectedStreams(unittest.TestCase):
716
def test_one_selected_stream(self):

0 commit comments

Comments
 (0)