Example #1
0
 def parse_spec(self, filepath):
     with open(filepath, encoding="utf-8") as file:
         filename = ntpath.basename(filepath)
         markdown_string = file.read()
         html = process_markdown(markdown_string)
         soup = BeautifulSoup(html, 'html.parser')
         spec_name = soup.find('h1').get_text()
         spec_name = re.sub(r'[^\w\s]', '', spec_name)
         scenario_titles = list(soup.findAll('h2'))
         steps = list(soup.findAll('ul'))
         scenarios = list()
         # Checking if there are any before steps
         if len(scenario_titles) != len(steps):
             scenario_steps = list()
             for step in steps[0].findAll('li'):
                 step_text = step.get_text()
                 scenario_steps.append(step_text)
             scenario = Scenario(name=f"Prerequisite {spec_name}", steps=scenario_steps, source_file=filename)
             scenarios.append(scenario)
             steps = steps[1:]
         for i in range(len(scenario_titles)):
             title = scenario_titles[i].get_text()
             scenario_steps = list()
             for step in steps[i].findAll('li'):
                 step_text = step.get_text()
                 scenario_steps.append(step_text)
             scenario = Scenario(name = title, steps=scenario_steps, source_file=filename)
             scenarios.append(scenario)
         return scenarios
Example #2
0
    def test_spec_title(self):
        with open(TEST_SPEC_PATH) as input_file:
            string = input_file.read()
            html = markdown_processor.process_markdown(string)
            soup = BeautifulSoup(html, 'html.parser')

            titles = list(soup.findAll("h1"))
            self.assertEqual(len(titles), 1)

            self.assertEqual(titles[0].get_text(), "Spec Title")
Example #3
0
    def test_scenario_names(self):
        with open(TEST_SPEC_PATH) as input_file:
            string = input_file.read()
            html = markdown_processor.process_markdown(string)
            soup = BeautifulSoup(html, 'html.parser')

            scenario_names = list(soup.findAll("h2"))

            self.assertEqual(len(scenario_names), 2)

            expected_scenario_names = ["Scenario 1", "Scenario 2"]

            for i, h2_element in enumerate(scenario_names):
                self.assertEqual(h2_element.get_text(),
                                 expected_scenario_names[i])
Example #4
0
 def parse_cpt(self, filepath):
     with open(filepath, encoding="utf-8") as file:
         markdown_string = file.read()
         html = process_markdown(markdown_string)
         soup = BeautifulSoup(html, "html.parser")
         cpt_names = list(soup.findAll('h1'))
         steps = list(soup.findAll('ul'))
         concepts = list()
         for i in range(len(cpt_names)):
             name = cpt_names[i].get_text()
             cpt_steps = list()
             for step in steps[i].findAll('li'):
                 cpt_steps.append(step.get_text())
             concept = Concept(name = name, steps=cpt_steps)
             concepts.append(concept)
         return concepts
Example #5
0
 def test_variables_replaced(self):
     with open(TEST_SPEC_PATH) as input_file:
         string = input_file.read()
         html = markdown_processor.process_markdown(string)
         self.assertTrue("$Variable$" in html)
Example #6
0
 def test_comments_removed(self):
     with open(TEST_SPEC_PATH) as input_file:
         string = input_file.read()
         html = markdown_processor.process_markdown(string)
         self.assertTrue("comment" not in html)