From 1fcfbe35c05b3d9ec0e22a58b886791a19e9a297 Mon Sep 17 00:00:00 2001 From: Sam Ruby Date: Mon, 25 Jun 2007 15:50:52 -0400 Subject: [PATCH] Omit category if term if blank --- planet/reconstitute.py | 4 ++-- tests/data/reconstitute/category_blank_term.xml | 11 +++++++++++ tests/data/reconstitute/category_label.xml | 2 +- tests/data/reconstitute/category_scheme.xml | 2 +- tests/reconstitute.py | 2 +- 5 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 tests/data/reconstitute/category_blank_term.xml diff --git a/planet/reconstitute.py b/planet/reconstitute.py index 3ab9cd8..c5123da 100644 --- a/planet/reconstitute.py +++ b/planet/reconstitute.py @@ -111,8 +111,8 @@ def date(xentry, name, parsed): def category(xentry, tag): xtag = xentry.ownerDocument.createElement('category') - if tag.has_key('term') and tag.term: - xtag.setAttribute('term', tag.get('term')) + if not tag.has_key('term') or not tag.term: return + xtag.setAttribute('term', tag.get('term')) if tag.has_key('scheme') and tag.scheme: xtag.setAttribute('scheme', tag.get('scheme')) if tag.has_key('label') and tag.label: diff --git a/tests/data/reconstitute/category_blank_term.xml b/tests/data/reconstitute/category_blank_term.xml new file mode 100644 index 0000000..564a740 --- /dev/null +++ b/tests/data/reconstitute/category_blank_term.xml @@ -0,0 +1,11 @@ + + + + + + + + diff --git a/tests/data/reconstitute/category_label.xml b/tests/data/reconstitute/category_label.xml index fc38fc7..4501d28 100644 --- a/tests/data/reconstitute/category_label.xml +++ b/tests/data/reconstitute/category_label.xml @@ -5,7 +5,7 @@ Expect: tags[0].label == 'Inbox' - + diff --git a/tests/data/reconstitute/category_scheme.xml b/tests/data/reconstitute/category_scheme.xml index b1cbbb4..81f3c93 100644 --- a/tests/data/reconstitute/category_scheme.xml +++ b/tests/data/reconstitute/category_scheme.xml @@ -5,7 +5,7 @@ Expect: tags[0].scheme == 'http://example.com/categories' - + diff --git a/tests/reconstitute.py b/tests/reconstitute.py index 4af8e77..dd57b92 100644 --- a/tests/reconstitute.py +++ b/tests/reconstitute.py @@ -41,7 +41,7 @@ if __name__ == "__main__": from planet import spider spider.spiderPlanet(only_if_new=False) - from planet import feedparser + import feedparser for source in glob.glob(os.path.join(work, 'sources/*')): feed = feedparser.parse(source).feed if feed.has_key('title'):