@@ -0,0 +1,2318 @@
+%22%22%22 Reading and representation of Instapaper spec files. %22%22%22%0A%0Aimport sys%0A%0Afrom saulify.clean import clean_content%0A%0A%0Aclass TestCase(object):%0A    %22%22%22%0A    Test case for the article scraper.%0A%0A    Attributes:%0A      url (str): URL of the page being tested%0A      fragments (list of str): Fragments of text that should be present in%0A        the output of the scraper.%0A    %22%22%22%0A%0A    def __init__(self, url):%0A        self.url = url%0A        self.fragments = %5B%5D%0A%0A    def add_contains(self, fragment):%0A        self.fragments.append(fragment)%0A%0A    def run(self):%0A        try:%0A            output = clean_content(self.url)%5B%22plaintext%22%5D%0A        except Exception as e:%0A            sys.stderr.write(%22Exception on %22 + self.url + %22 :%5Cn%22)%0A            sys.stderr.write(str(e))%0A            return %7B%0A                %22url%22: self.url,%0A                %22status%22: %22EXCEPTION%22,%0A                %22message%22: %22e.message%22%0A            %7D%0A        else:%0A            return %7B%0A                %22url%22: self.url,%0A                %22status%22: %22OK%22,%0A                %22missing_fragments%22: self.missing_fragments(output),%0A            %7D%0A%0A    def missing_fragments(self, text):%0A        missing = %5B%5D%0A        for s in self.fragments:%0A            if s not in text:%0A                missing.append(s)%0A        return missing%0A%0A%0Adef load_testcases(fpath):%0A    %22%22%22%0A    Reads test cases from an Instapaper spec file.%0A%0A    Scans file until it reaches a line labelled %22test_url%22, then creates a%0A    new %60%60TestCase%60%60 object. Subsequent lines populate the test case.%0A    Multiple test cases in a single file are supported.%0A%0A    Args:%0A      fpath: Path to the spec file.%0A%0A    Returns:%0A      A list of %60%60TestCase%60%60 objects.%0A    %22%22%22%0A%0A    def parse_specline(line):%0A        parts = line.partition(':')%0A        label = parts%5B0%5D%0A        content = parts%5B2%5D.strip()%0A        return (label, content)%0A%0A    cases = %5B%5D%0A%0A    with open(fpath) as f:%0A        for line in f:%0A            (label, content) = parse_specline(line)%0A            if label == %22test_url%22:%0A                url = content%0A                case = TestCase(url)%0A                cases.append(case)%0A            elif label == %22test_contains%22:%0A                if not cases:%0A                    raise Exception(%22Invalid spec file: %22 + fpath)%0A                fragment = content%0A                cases%5B-1%5D.add_contains(fragment)%0A%0A    return cases%0A

Add module handling Instapaper config files