Exemplo n.º 1
0
def test_basic_categorization():

    db.subjects.insert({"abbr": "ex", "remote": "AK-47", "normal": ["Guns", "Crime"]})
    db.subjects.insert({"abbr": "ex", "remote": "Hunting", "normal": ["Guns"]})
    db.subjects.insert({"abbr": "ex", "remote": "Candy", "normal": ["Food"]})

    categorizer = SubjectCategorizer("ex")

    # simple
    bill = {"scraped_subjects": ["AK-47"]}
    categorizer.categorize_bill(bill)
    assert_equal(bill, {"scraped_subjects": ["AK-47"], "subjects": [u"Guns", u"Crime"]})

    # no subjects
    bill = {"scraped_subjects": ["Welfare"]}
    categorizer.categorize_bill(bill)
    assert_equal(bill, {"scraped_subjects": ["Welfare"], "subjects": []})

    # two subjects
    bill = {"scraped_subjects": ["AK-47", "Candy"]}
    categorizer.categorize_bill(bill)
    assert_equal(set(bill["subjects"]), set([u"Guns", u"Crime", u"Food"]))

    # avoid duplicates
    bill = {"scraped_subjects": ["AK-47", "Hunting"]}
    categorizer.categorize_bill(bill)
    assert_equal(bill, {"scraped_subjects": ["AK-47", "Hunting"], "subjects": [u"Guns", u"Crime"]})
Exemplo n.º 2
0
def test_basic_categorization():

    db.subjects.insert({'abbr': 'ex', 'remote': 'AK-47',
                        'normal': ['Guns', 'Crime']})
    db.subjects.insert({'abbr': 'ex', 'remote': 'Hunting', 'normal': ['Guns']})
    db.subjects.insert({'abbr': 'ex', 'remote': 'Candy', 'normal': ['Food']})

    categorizer = SubjectCategorizer('ex')

    # simple
    bill = {'scraped_subjects': ['AK-47']}
    categorizer.categorize_bill(bill)
    assert_equal(bill, {'scraped_subjects': ['AK-47'],
                        'subjects': [u'Guns', u'Crime']})

    # no subjects
    bill = {'scraped_subjects': ['Welfare']}
    categorizer.categorize_bill(bill)
    assert_equal(bill, {'scraped_subjects': ['Welfare'],
                        'subjects': []})

    # two subjects
    bill = {'scraped_subjects': ['AK-47', 'Candy']}
    categorizer.categorize_bill(bill)
    assert_equal(set(bill['subjects']), set([u'Guns', u'Crime', u'Food']))

    # avoid duplicates
    bill = {'scraped_subjects': ['AK-47', 'Hunting']}
    categorizer.categorize_bill(bill)
    assert_equal(bill, {'scraped_subjects': ['AK-47', 'Hunting'],
                        'subjects': [u'Guns', u'Crime']})
Exemplo n.º 3
0
def test_basic_categorization():

    db.subjects.insert({'abbr': 'ex', 'remote': 'AK-47',
                        'normal': ['Guns', 'Crime']})
    db.subjects.insert({'abbr': 'ex', 'remote': 'Hunting', 'normal': ['Guns']})
    db.subjects.insert({'abbr': 'ex', 'remote': 'Candy', 'normal': ['Food']})

    categorizer = SubjectCategorizer('ex')

    # simple
    bill = {'scraped_subjects': ['AK-47']}
    categorizer.categorize_bill(bill)
    bill['subjects'] = sorted(bill['subjects'])

    assert_equal(bill, {'scraped_subjects': ['AK-47'],
                        'subjects': [u'Crime', u'Guns']})

    # no subjects
    bill = {'scraped_subjects': ['Welfare']}
    categorizer.categorize_bill(bill)
    bill['subjects'] = sorted(bill['subjects'])
    assert_equal(bill, {'scraped_subjects': ['Welfare'],
                        'subjects': []})

    # two subjects
    bill = {'scraped_subjects': ['AK-47', 'Candy']}
    categorizer.categorize_bill(bill)
    bill['subjects'] = sorted(bill['subjects'])
    assert_equal(bill['subjects'], [u'Crime', u'Food', u'Guns'])

    # avoid duplicates
    bill = {'scraped_subjects': ['AK-47', 'Hunting']}
    categorizer.categorize_bill(bill)
    bill['subjects'] = sorted(bill['subjects'])
    assert_equal(bill, {'scraped_subjects': ['AK-47', 'Hunting'],
                        'subjects': [u'Crime', u'Guns']})