def test_find_volume(self, Volume):
        v1 = Mock()
        v1.exists = True
        v1.should_contain.return_value = False

        v2 = Mock()
        v2.exists = True
        v2.should_contain.return_value = True

        v3 = Mock()
        v3.exists = False

        def side_effect(year, title, vol_num):
            if vol_num > 3:
                return v2
            return v1

        Volume.side_effect = side_effect

        self.assertEqual(annual.find_volume(2000, 11, 3), v2)

        def side_effect(year, title, vol_num):
            if vol_num > 3:
                return v3
            return v1

        Volume.side_effect = side_effect
        self.assertEqual(annual.find_volume(2000, 11, 3), None)
    def test_find_volume(self, Volume):
        v1 = Mock()
        v1.exists = True
        v1.should_contain.return_value = False

        v2 = Mock()
        v2.exists = True
        v2.should_contain.return_value = True

        v3 = Mock()
        v3.exists = False

        def side_effect(year, title, vol_num):
            if vol_num > 3:
                return v2
            return v1

        Volume.side_effect = side_effect

        self.assertEqual(annual.find_volume(2000, 11, 3), v2)

        def side_effect(year, title, vol_num):
            if vol_num > 3:
                return v3
            return v1

        Volume.side_effect = side_effect
        self.assertEqual(annual.find_volume(2000, 11, 3), None)
def current_version(cfr_title, cfr_part):
    """Build a regulation tree for the most recent annual edition. This will
    also construct a corresponding, empty notice to match. The version will be
    marked as effective _today_"""

    year = date.today().year
    vol = find_volume(year, cfr_title, cfr_part)
    if vol is None:
        year -= 1
        vol = find_volume(year, cfr_title, cfr_part)

    create_version_entry_if_needed(cfr_title, cfr_part, year)
    process_if_needed(cfr_title, cfr_part, year)
def current_version(cfr_title, cfr_part):
    """Build a regulation tree for the most recent annual edition. This will
    also construct a corresponding, empty notice to match. The version will be
    marked as effective on the date of the last annual edition (which is not
    likely accurate)"""
    year = date.today().year
    vol = find_volume(year, cfr_title, cfr_part)
    if vol is None:
        year -= 1
        vol = find_volume(year, cfr_title, cfr_part)

    logger.info("Getting current version - %s CFR %s, Year: %s", cfr_title, cfr_part, year)

    create_version_entry_if_needed(vol, cfr_part)
    process_if_needed(vol, cfr_part)
Exemplo n.º 5
0
def current_version(cfr_title, cfr_part):
    """Build a regulation tree for the most recent annual edition. This will
    also construct a corresponding, empty notice to match. The version will be
    marked as effective on the date of the last annual edition (which is not
    likely accurate)"""
    year = date.today().year
    vol = find_volume(year, cfr_title, cfr_part)
    if vol is None:
        year -= 1
        vol = find_volume(year, cfr_title, cfr_part)

    logger.info("Getting current version - %s CFR %s, Year: %s", cfr_title,
                cfr_part, year)

    create_version_entry_if_needed(vol, cfr_part)
    process_if_needed(vol, cfr_part)
def fetch_annual_edition(cfr_title, cfr_part, year):
    """Download an annual edition of a regulation"""
    volume = annual.find_volume(year, cfr_title, cfr_part)
    xml = volume.find_part_xml(cfr_part).preprocess()
    annual_entry = entry.Annual(cfr_title, cfr_part, year)
    annual_entry.write(xml)
    if xml.source_is_local:
        dependency.Graph().add(str(annual_entry), xml.source)
Exemplo n.º 7
0
def fetch_annual_edition(cfr_title, cfr_part, year):
    """Download an annual edition of a regulation"""
    volume = annual.find_volume(year, cfr_title, cfr_part)
    xml = volume.find_part_xml(cfr_part).preprocess()
    annual_entry = entry.Annual(cfr_title, cfr_part, year)
    annual_entry.write(xml)
    if xml.source_is_local:
        dependency.Graph().add(str(annual_entry), xml.source)
Exemplo n.º 8
0
def annual_version(cfr_title, cfr_part, year):
    """Build a regulation tree for the most recent annual edition. This will
    also construct a corresponding, empty notice to match. The version will be
    marked as effective on the date of the last annual edition (which is not
    likely accurate)"""
    cfr_year = year or date.today().year
    vol = find_volume(cfr_year, cfr_title, cfr_part)
    if vol is None and year is None:
        logger.warning("No annual edition for %s CFR %s, Year: %s. Trying %s.",
                       cfr_title, cfr_part, cfr_year, cfr_year - 1)
        cfr_year -= 1
        vol = find_volume(cfr_year, cfr_title, cfr_part)

    if vol is None:
        logger.error("No annual edition for %s CFR %s, Year: %s", cfr_title,
                     cfr_part, cfr_year)
    else:
        logger.info("Getting annual version - %s CFR %s, Year: %s", cfr_title,
                    cfr_part, cfr_year)

        create_version_entry_if_needed(vol, cfr_part)
        process_if_needed(vol, cfr_part)
def last_versions(cfr_title, cfr_part):
    """Run through all known versions of this regulation and pull out versions
    which are the last to be included before an annual edition"""
    have_annual_edition = {}
    path = entry.FinalVersion(cfr_title, cfr_part)
    if len(path) == 0:
        raise click.UsageError("No versions found. Run `versions`?")
    for version_id in path:
        version = (path / version_id).read()
        pub_date = annual.date_of_annual_after(cfr_title, version.effective)
        have_annual_edition[pub_date.year] = version.identifier
    for year in sorted(have_annual_edition.keys()):
        if annual.find_volume(year, cfr_title, cfr_part):
            yield LastVersionInYear(have_annual_edition[year], year)
        else:
            logger.warning("%s edition for %s CFR %s not published yet", year, cfr_title, cfr_part)
Exemplo n.º 10
0
def last_versions(cfr_title, cfr_part):
    """Run through all known versions of this regulation and pull out versions
    which are the last to be included before an annual edition"""
    have_annual_edition = {}
    path = entry.FinalVersion(cfr_title, cfr_part)
    if not any(path.sub_entries()):
        raise click.UsageError("No versions found. Run `versions`?")
    for subpath in path.sub_entries():
        version = subpath.read()
        pub_date = annual.date_of_annual_after(cfr_title, version.effective)
        have_annual_edition[pub_date.year] = version.identifier
    for year in sorted(have_annual_edition):
        if annual.find_volume(year, cfr_title, cfr_part):
            yield LastVersionInYear(have_annual_edition[year], year)
        else:
            logger.warning("%s edition for %s CFR %s not published yet", year,
                           cfr_title, cfr_part)
def fetch_annual_edition(cfr_title, cfr_part, year):
    """Download an annual edition of a regulation"""
    volume = annual.find_volume(year, cfr_title, cfr_part)
    xml = volume.find_part_xml(cfr_part).preprocess()
    annual_entry = entry.Annual(cfr_title, cfr_part, year)
    annual_entry.write(xml)
Exemplo n.º 12
0
def fetch_annual_edition(cfr_title, cfr_part, year):
    """Download an annual edition of a regulation"""
    volume = annual.find_volume(year, cfr_title, cfr_part)
    xml = volume.find_part_xml(cfr_part).preprocess()
    annual_entry = entry.Annual(cfr_title, cfr_part, year)
    annual_entry.write(xml)