Example #1
0
def generate_tests(scenarios, macros_mgr=None, propagate=False):
    """Create a test suite from a YAML file (suite or scenario).

    :param scenario_file: A list of YAML scenario file path.
    :param macros_mgr:    MacrosManager with macros already defined

    :returns suite:       A unittest TestSuite object.
    :returns configs:     Scenarios config blocks.
    """
    suite = SelectableTestSuite()

    # get data from scenarios
    ## read the first file
    tests_data = ScenarioReader(scenarios.pop(0),
                                macros_mgr=macros_mgr,
                                propagate=propagate).get_deserialized()
    if "scenarios" not in tests_data:
        tests_data["scenarios"] = []
    ## append scenario from remaining files
    for scenario in scenarios:
        new_tests_data = ScenarioReader(
            scenario, macros_mgr=macros_mgr,
            propagate=propagate).get_deserialized()
        tests_data["scenarios"] += new_tests_data["scenarios"]

    # Get titles
    ## Defaults title when several files from command line.
    configs = [{"name": "WeTest Suite"}]
    ## Overwise get top title from first file
    if len(scenarios) == 0 and "name" in tests_data:
        configs = [{"name": tests_data["name"]}]
    # and populate TestSuite
    for idx, scenario in enumerate(tests_data['scenarios']):
        logger.debug("Generate tests with TestGenerator...")
        tests_gen = TestsGenerator(scenario)
        configs.append(tests_gen.get_config())

        logger.debug("Append tests to suite...")
        tests_gen.append_to_suite(suite, scenario_index=idx)

    logger.debug("Created tests suite.")

    # display unit/functionnal info to user
    logger.warning("Loaded %s tests from `%s`:", suite.countTestCases(),
                   configs[0]["name"])
    for scenario in tests_data['scenarios']:
        if str(scenario["config"]["type"]).lower() == "unit":
            type_str = "unit tests (random)  "
        elif str(scenario["config"]["type"]).lower() == "functional":
            type_str = "functional (ordered) "
        else:
            type_str = str(scenario["config"]["type"]) + " (??)"
        logger.warning("\t- %s `%s`", type_str,
                       scenario["config"].get("name", "Unnamed"))

    return suite, configs
Example #2
0
 def test_get_setter(self):
     """Setter is correctly defined."""
     scenario = ScenarioReader("wetest/tests/scenario_example03.yaml")
     tests = TestsGenerator(scenario.get_deserialized())
     setter = get_key(tests.data["tests"][0]["commands"][0],
                      tests.data["tests"][0], "setter")
     self.assertEqual("LockS", setter)
     getter = get_key(tests.data["tests"][0]["commands"][0],
                      tests.data["tests"][0], "getter")
     self.assertEqual("LockR", getter)
Example #3
0
 def test_scenario_mks946_syntax(self):
     self.assertEqual(True,
                      ScenarioReader("wetest/tests/mks946.yaml").is_valid())
Example #4
0
 def test_scenario_acceptance_demo_syntax(self):
     self.assertEqual(
         True,
         ScenarioReader("wetest/tests/acceptance-demo.yaml").is_valid())
Example #5
0
 def test_scenario_example05_syntax(self):
     self.assertEqual(
         True,
         ScenarioReader("wetest/tests/scenario_example05.yaml").is_valid())
Example #6
0
 def test_get_prefix(self):
     """Prefix is correctly assembled from prefix fields."""
     scenario = ScenarioReader("wetest/tests/scenario_example03.yaml")
     tests = TestsGenerator(scenario.get_deserialized())
     self.assertEqual("LOCATION:DEVICE:", tests.tests_list[0][0].prefix)
Example #7
0
 def test_device_prefix(self):
     """Device prefix is correctyl used."""
     scenario = ScenarioReader("wetest/tests/scenario_example03.yaml")
     tests = TestsGenerator(scenario.get_deserialized())
     tests.generates(TestsSequence)
Example #8
0
 def test_generator(self):
     """Test generator can read and generates tests."""
     scenario = ScenarioReader("wetest/tests/mks946.yaml")
     tests = TestsGenerator(scenario.get_deserialized())
     tests.generates(TestsSequence)