<commit_before>from unittest import TestCase

from clarify.jurisdiction import Jurisdiction

class TestJurisdiction(TestCase):
    def test_construct(self):
        url = 'http://results.enr.clarityjurisdictions.com/KY/15261/30235/en/summary.html'
        jurisdiction = Jurisdiction(url=url, level='state')
        self.assertEqual(jurisdiction.url, url)

    def test_get_subjurisdictions_state(self):
        # subjurisdiction url path is in script tag
        # Construct a Jurisdiction for Kentucky's 2014 Primary Election
        url = 'http://results.enr.clarityelections.com/KY/50972/131636/en/summary.html'
        jurisdiction = Jurisdiction(url=url, level='state')
        jurisdictions = jurisdiction.get_subjurisdictions()
        # Kentucky has 120 counties
        expected_jurisdiction_count = 120
        self.assertEqual(len(jurisdictions), expected_jurisdiction_count)
        for jurisdiction in jurisdictions:
            # The sub-jurisdictions of a state are counties
            self.assertEqual(jurisdiction.level, 'county')
            # The sub-jurisdictions should have a url attribute set
            self.assertIsNotNone(jurisdiction.url)

    def test_get_subjurisdictions_state_meta(self):
        # subjurisdiction url path is in meta tag
        # Construct a Jurisdiction for Kentucky's 2010 Primary Election
        url = 'http://results.enr.clarityelections.com/KY/15261/30235/en/summary.html'
        jurisdiction = Jurisdiction(url=url, level='state')
        jurisdictions = jurisdiction.get_subjurisdictions()
        # Kentucky has 120 counties
        expected_jurisdiction_count = 120
        self.assertEqual(len(jurisdictions), expected_jurisdiction_count)
        for jurisdiction in jurisdictions:
            # The sub-jurisdictions of a state are counties
            self.assertEqual(jurisdiction.level, 'county')
            # The sub-jurisdictions should have a url attribute set
            self.assertIsNotNone(jurisdiction.url)

    def test_get_sub_jurisdictions_none(self):
        """A jurisdiction with no sub-jurisdictions should return an empty list"""
        # Construct a Jurisdiction for Rockford City, IL 2014 General Election
        url = 'http://results.enr.clarityelections.com/IL/Rockford/54234/148685/en/summary.html'
        jurisdiction = Jurisdiction(url=url, level='city')
        jurisdictions = jurisdiction.get_subjurisdictions()
        # A city has no sub-jurisdictions with results
        expected_jurisdiction_count = 0
        self.assertEqual(len(jurisdictions), expected_jurisdiction_count)

    def test_get_sub_jurisdictions_none_web01(self):
        """A jurisdiction with no sub-jurisdictions with Web01 in url should return an empty list"""
        # Construct a Jurisdiction for Middlesex County, NJ 2013 General Election
        url = 'http://results.enr.clarityelections.com/NJ/Middlesex/46982/117336/Web01/en/summary.html'
        jurisdiction = Jurisdiction(url=url, level='county')
        jurisdictions = jurisdiction.get_subjurisdictions()
        # A city has no sub-jurisdictions with results
        expected_jurisdiction_count = 0
        self.assertEqual(len(jurisdictions), expected_jurisdiction_count)

    def test_report_url_xml(self):
        # Construct a Jurisdiction for Appling County, GA 2014 Primary Election
        url = 'http://results.enr.clarityelections.com/GA/Appling/52178/139522/en/summary.html'
        jurisdiction = Jurisdiction(url=url, level='county')
        expected_url = 'http://results.enr.clarityelections.com/GA/Appling/52178/139522/reports/detailxml.zip'
        self.assertEqual(jurisdiction.report_url('xml'), expected_url)

    def test_report_url_txt(self):
        # Construct a Jurisdiction for Kentucky 2010 Primary Election
        url = 'http://results.enr.clarityelections.com/KY/15261/30235/en/summary.html'
        jurisdiction = Jurisdiction(url=url, level='county')<commit_msg>added test for Web01 urls<commit_after>from unittest import TestCase

from clarify.jurisdiction import Jurisdiction

class TestJurisdiction(TestCase):
    def test_construct(self):
        url = 'http://results.enr.clarityjurisdictions.com/KY/15261/30235/en/summary.html'
        jurisdiction = Jurisdiction(url=url, level='state')
        self.assertEqual(jurisdiction.url, url)

    def test_get_subjurisdictions_state(self):
        # subjurisdiction url path is in script tag
        # Construct a Jurisdiction for Kentucky's 2014 Primary Election
        url = 'http://results.enr.clarityelections.com/KY/50972/131636/en/summary.html'
        jurisdiction = Jurisdiction(url=url, level='state')
        jurisdictions = jurisdiction.get_subjurisdictions()
        # Kentucky has 120 counties
        expected_jurisdiction_count = 120
        self.assertEqual(len(jurisdictions), expected_jurisdiction_count)
        for jurisdiction in jurisdictions:
            # The sub-jurisdictions of a state are counties
            self.assertEqual(jurisdiction.level, 'county')
            # The sub-jurisdictions should have a url attribute set
            self.assertIsNotNone(jurisdiction.url)

    def test_get_subjurisdictions_state_meta(self):
        # subjurisdiction url path is in meta tag
        # Construct a Jurisdiction for Kentucky's 2010 Primary Election
        url = 'http://results.enr.clarityelections.com/KY/15261/30235/en/summary.html'
        jurisdiction = Jurisdiction(url=url, level='state')
        jurisdictions = jurisdiction.get_subjurisdictions()
        # Kentucky has 120 counties
        expected_jurisdiction_count = 120
        self.assertEqual(len(jurisdictions), expected_jurisdiction_count)
        for jurisdiction in jurisdictions:
            # The sub-jurisdictions of a state are counties
            self.assertEqual(jurisdiction.level, 'county')
            # The sub-jurisdictions should have a url attribute set
            self.assertIsNotNone(jurisdiction.url)

    def test_get_sub_jurisdictions_none(self):
        """A jurisdiction with no sub-jurisdictions should return an empty list"""
        # Construct a Jurisdiction for Rockford City, IL 2014 General Election
        url = 'http://results.enr.clarityelections.com/IL/Rockford/54234/148685/en/summary.html'
        jurisdiction = Jurisdiction(url=url, level='city')
        jurisdictions = jurisdiction.get_subjurisdictions()
        # A city has no sub-jurisdictions with results
        expected_jurisdiction_count = 0
        self.assertEqual(len(jurisdictions), expected_jurisdiction_count)

    def test_get_sub_jurisdictions_none_web01(self):
        """A jurisdiction with no sub-jurisdictions with Web01 in url should return an empty list"""
        # Construct a Jurisdiction for Middlesex County, NJ 2013 General Election
        url = 'http://results.enr.clarityelections.com/NJ/Middlesex/46982/117336/Web01/en/summary.html'
        jurisdiction = Jurisdiction(url=url, level='county')
        jurisdictions = jurisdiction.get_subjurisdictions()
        # A city has no sub-jurisdictions with results
        expected_jurisdiction_count = 0
        self.assertEqual(len(jurisdictions), expected_jurisdiction_count)

    def test_get_sub_jurisdictions_web01(self):
        """A jurisdiction with sub-jurisdictions with Web01 in url should return a list"""
        # Construct a Jurisdiction for Arkansas 2014 General Election
        url = 'http://results.enr.clarityelections.com/AR/53237/149294/Web01/en/summary.html'
        jurisdiction = Jurisdiction(url=url, level='state')
        jurisdictions = jurisdiction.get_subjurisdictions()
        # A city has no sub-jurisdictions with results
        expected_jurisdiction_count = 75
        self.assertEqual(len(jurisdictions), expected_jurisdiction_count)

    def test_report_url_xml(self):
        # Construct a Jurisdiction for Appling County, GA 2014 Primary Election
        url = 'http://results.enr.clarityelections.com/GA/Appling/52178/139522/en/summary.html'
        jurisdiction = Jurisdiction(url=url, level='county')
        expected_url = 'http://results.enr.clarityelections.com/GA/Appling/52178/139522/reports/detailxml.zip'
        self.assertEqual(jurisdiction.report_url('xml'), expected_url)

    def test_report_url_txt(self):
        # Construct a Jurisdiction for Kentucky 2010 Primary Election
        url = 'http://results.enr.clarityelections.com/KY/15261/30235/en/summary.html'
        jurisdiction = Jurisdiction(url=url, level='county')
{'fraction_non_alphanumeric': 0.08410111032364753, 'fraction_numerical': 0.033427828962910466, 'mean_word_length': 3.3779731127197516, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3596932', 'n_tokens_mistral': 2799, 'n_tokens_neox': 2319, 'n_words': 537}