예제 #1
0
    def test_error_zipped_folder(self):
        attrs = {
            "name": "name",
            "root-path": "/home/test",
            "type": "multiple-files",
            "zip": True,
        }

        with pytest.raises(AutomaticEntryError,
                           match="Must provide 'zipname'"):
            check_yaml_entry(**attrs)
예제 #2
0
    def test_missing_multiple_attrs(self, attrs, missing):
        set_missing = list(permutations(missing))
        set_missing = [
            "{" + "%s" % ", ".join(repr(k) for k in x) + "}"
            for x in set_missing
        ]
        name = "null" if "name" in missing else "name"
        set_missing = f"({'|'.join(set_missing)})"
        msg = f"Missing required attributes in query {name}: {set_missing}"

        for key in missing:
            del attrs[key.replace("_", "-")]
        with pytest.raises(AutomaticEntryError, match=msg):
            check_yaml_entry(**attrs)
예제 #3
0
    def test_invalid_types(self, attrs, attribute):
        for attr in ATTRS_TYPES:
            if attr == attribute:
                continue
            if attr in attrs:
                continue
            attrs[attr] = ATTRS_TYPES[attr](2)
        attrs[attribute] = 1 + 2j

        match = (
            f"{attribute!r} must be {ATTRS_TYPES[attribute].__name__!r}, not 'complex'"
        )
        if attribute not in REQUIRED_ATTRS:
            match = "If defined, " + match
        with pytest.raises(TypeError, match=match):
            check_yaml_entry(**attrs)
예제 #4
0
 def test_ok_basic(self, attrs):
     result = check_yaml_entry(**attrs)
     assert result == {
         "name": "name",
         "root_path": "/home/test",
         "type": "single-file",
     }
예제 #5
0
 def test_ok_unzipped_folder(self):
     attrs = {
         "name": "name",
         "root-path": "/home/test",
         "type": "multiple-files",
         "zip": False,
         "zipname": "a.zip",
     }
     result = check_yaml_entry(**attrs)
     assert result == {
         "name": "name",
         "root_path": "/home/test",
         "type": "multiple-files",
         "zip": False,
         "zipname": "a.zip",
     }
예제 #6
0
 def test_invalid_entry_type(self, attrs):
     attrs["type"] = "invalid-type"
     with pytest.raises(TypeError,
                        match="'invalid-type' is not a valid Entrytype"):
         check_yaml_entry(**attrs)
예제 #7
0
 def test_missing_attrs(self, attrs, missing):
     name = "null" if missing == "name" else "name"
     msg = f"Missing required attributes in query {name}: {set([missing])!r}"
     del attrs[missing.replace("_", "-")]
     with pytest.raises(AutomaticEntryError, match=msg):
         check_yaml_entry(**attrs)
예제 #8
0
 def test_invalid_attrs(self, attrs):
     attrs["invalid"] = True
     with pytest.raises(AutomaticEntryError,
                        match=r"'invalid' is not a valid attribute"):
         check_yaml_entry(**attrs)