def test_write_to_markdown_file(self): today = datetime.datetime.today() month = today.month date = today.day year = today.year date_str = "Updated on: {0}-{1}-{2}\n\n".format(date, month, year) targetdir = "/Users/lemon/Dropbox/Textnotes/" mdfile = "100greatestnovels.md" with open(os.path.join(targetdir, mdfile), "w", encoding='utf-8') as f: f.write('{0}\n\n{1}\n\n{2}\n\n'.format("#The Guardian 100 best Novels", "To update this go into project folder and run `python3 hundredgreatest.py`", "##The list")) f.write("\n{0}".format(date_str)) d = hundredgreatest.get_novel_link_title_pairs() for k in d: f.write('[{0}]({1})\n\n'.format(d.get(k), k)) f.write("\n\n\nThere are {0} novels in the list".format(len(d))) with open(os.path.join(targetdir, mdfile), "rb") as f: checksum = binascii.crc32(f.read()) print("TEST Markdown file checksum: {0}\nMODULE Markdown file checksum: {1}".format(checksum, hundredgreatest.write_to_markdown_file())) self.assertEqual(checksum, hundredgreatest.write_to_markdown_file())
def test_for_novel_link_title_pairs(self): all_links = [] for c in hundredgreatest.get_all_compiled_links( hundredgreatest.raw_compiled_soups( hundredgreatest.setup(hundredgreatest.BASEURL))): for l in c: all_links.append(l) regex_for_all_links = re.compile(r"<a.*\"(.*)\">(.*)</a>") regex_for_novel_titles = re.compile(r"<a.*>(The 100 best novels: No.*)</a>") novel_only_titles = [] list_of_link_texts = [] list_of_link_urls = [] for link in all_links: r = re.search(regex_for_all_links, link) rn = re.search(regex_for_novel_titles, link) if r: if rn: list_of_link_texts.append(r.group(2)) list_of_link_urls.append(r.group(1)) novel_only_titles.append(rn.group(1)) dict_of_text_links = dict(zip(list_of_link_urls, list_of_link_texts)) self.assertEqual(hundredgreatest.get_novel_link_title_pairs(), dict_of_text_links)