Example #1
0
def load_panchaanga(fname, fallback_fn):
    logging.info('Loaded pre-computed panchaanga from %s.\n' % fname)
    panchaanga = Panchaanga.read_from_file(
        filename=fname,
        name_to_json_class_index_extra={"Panchangam": periodical.Panchaanga})
    if getattr(
            panchaanga, 'version', None
    ) is None or panchaanga.version != periodical.Panchaanga.LATEST_VERSION:
        logging.warning("Precomputed Panchanga obsolete.")
        return fallback_fn()
    else:
        panchaanga.dump_to_file(filename=fname)
        return panchaanga
Example #2
0
def test_panchanga_chennai_2019():
  panchaanga_2019 = Panchaanga.read_from_file(filename=os.path.join(TEST_DATA_PATH, 'Chennai-2019.json'))
  panchaanga_2019.update_festival_details()
  orig_ics_file = os.path.join(TEST_DATA_PATH, 'Chennai-2019-devanagari.ics')
  current_ics_output = os.path.join(TEST_DATA_PATH, 'Chennai-2019-devanagari.ics.local')
  ics_calendar = compute_calendar(panchaanga_2019, scripts=[sanscript.IAST])
  write_to_file(ics_calendar, current_ics_output)
  if not os.path.exists(orig_ics_file):
    logging.warning("%s not present. Assuming that it was deliberately deleted to update test files.", orig_ics_file)
    write_to_file(ics_calendar, orig_ics_file)
    

  with open(orig_ics_file) as orig_tex:
    with open(current_ics_output) as current_tex:
      assert current_tex.read() == orig_tex.read()
Example #3
0
def load_panchaanga(fname, fallback_fn):
    logging.info('Loaded pre-computed panchaanga from %s.\n' % fname)
    panchaanga = Panchaanga.read_from_file(
        filename=fname,
        name_to_json_class_index_extra={"Panchangam": periodical.Panchaanga})
    if getattr(
            panchaanga, 'version', None
    ) is None or panchaanga.version != periodical.Panchaanga.LATEST_VERSION:
        logging.warning("Precomputed Panchanga obsolete.")
        return fallback_fn()
    else:
        # Festival data may be updated more frequently and a precomputed panchaanga may go out of sync. Hence we keep this method separate.
        panchaanga.update_festival_details()
        panchaanga.dump_to_file(filename=fname)
        return panchaanga
Example #4
0
def test_panchanga_chennai_2019():
    panchaanga_2019 = Panchaanga.read_from_file(
        filename=os.path.join(TEST_DATA_PATH, 'Chennai-2019.json'))
    # We dump to md.txt rather than md to avoid slow checks on intellij ide.
    orig_md_file = os.path.join(TEST_DATA_PATH,
                                'Chennai-2019-devanagari.md.txt')
    current_md_output = os.path.join(TEST_DATA_PATH,
                                     'Chennai-2019-devanagari.md.txt.local')
    md_file = MdFile(file_path=current_md_output)
    md_file.dump_to_file(metadata={"title": str(2019)},
                         content=md.make_md(panchaanga=panchaanga_2019),
                         dry_run=False)
    if not os.path.exists(orig_md_file):
        logging.warning(
            "%s not present. Assuming that it was deliberately deleted to update test files.",
            orig_md_file)
        md_file = MdFile(file_path=orig_md_file)
        md_file.dump_to_file(metadata={"title": str(2019)},
                             content=md.make_md(panchaanga=panchaanga_2019),
                             dry_run=False)

    with open(orig_md_file) as orig_tex:
        with open(current_md_output) as current_tex:
            assert current_tex.read() == orig_tex.read()
def daily_tex_comparer(city_name, year):
    panchaanga = Panchaanga.read_from_file(
        filename=os.path.join(TEST_DATA_PATH, '%s-%s.json' %
                              (city_name, year)))
    panchaanga.update_festival_details()
    orig_tex_file = os.path.join(
        TEST_DATA_PATH, 'daily-cal-%s-%s-deva.tex' % (year, city_name))
    current_tex_output = os.path.join(
        TEST_DATA_PATH, 'daily-cal-%s-%s-deva.tex.local' % (year, city_name))
    emit(panchaanga,
         output_stream=open(current_tex_output, 'w'),
         scripts=[sanscript.DEVANAGARI, sanscript.TAMIL])

    if not os.path.exists(orig_tex_file):
        logging.warning(
            "Files must have been deliberately deleted due to changed expectation. We'll just set it for future tests."
        )
        emit(panchaanga,
             output_stream=open(orig_tex_file, 'w'),
             scripts=[sanscript.DEVANAGARI, sanscript.TAMIL])
    else:
        with open(orig_tex_file) as orig_tex:
            with open(current_tex_output) as current_tex:
                assert current_tex.read() == orig_tex.read()