Exemplo n.º 1
0
class TestJCVersion:
    @pytest.mark.parametrize(
        "version,major,minor",
        [
            ("0000", 0, 0),
            ("0100", 1, 0),
            ("0202", 2, 2),
            ("0201", 2, 1),
            ("0300", 3, 0),
        ],
    )
    def test_from_str(self, version: str, major: int, minor: int):
        jcversion = JCVersion.from_str(version)

        assert jcversion.major == major
        assert jcversion.minor == minor

    @pytest.mark.parametrize(
        "version,string",
        [
            ("0000", "0.0"),
            ("0100", "1.0"),
            ("0202", "2.2"),
            ("0201", "2.1"),
            ("0300", "3.0"),
        ],
    )
    def test___str__(self, version: str, string: str):
        jcversion = JCVersion.from_str(version)
        assert str(jcversion) == string

    @pytest.mark.parametrize(
        "jcversion,exp_sdks",
        [
            ("0200", SDKVersion.from_list("jc202")),
            ("0300", SDKVersion.from_list("jc202,jc300,jc301,jc304")),
            ("0310", SDKVersion.from_list("jc202,jc300,jc301,jc304,jc310b43")),
        ],
    )
    def test_get_sdks(self, mocker, jcversion, exp_sdks):
        # mocking available SDKs
        mocker.patch.object(SDKVersion, "get_available_sdks")
        SDKVersion.get_available_sdks.return_value = SDKVersion.from_list(
            "jc202,jc300,jc301,jc304,jc310b43")

        jcversion = JCVersion.from_str(jcversion)
        sdks = jcversion.get_sdks()
        assert sdks == exp_sdks
Exemplo n.º 2
0
 def possible_versions(self) -> List["SDKVersion"]:
     """
     Returns the intersection of SDKVersions the attack can be build for
     and the ones supported by the Card
     """
     attack_sdk_versions = SDKVersion.from_list(
         self.config["BUILD"]["versions"], sep=",")
     return list(set(attack_sdk_versions).intersection(set(self.card.sdks)))
Exemplo n.º 3
0
    def test_get_sdks(self, mocker, jcversion, exp_sdks):
        # mocking available SDKs
        mocker.patch.object(SDKVersion, "get_available_sdks")
        SDKVersion.get_available_sdks.return_value = SDKVersion.from_list(
            "jc202,jc300,jc301,jc304,jc310b43")

        jcversion = JCVersion.from_str(jcversion)
        sdks = jcversion.get_sdks()
        assert sdks == exp_sdks
Exemplo n.º 4
0
 def _determine_version(self) -> "SDKVersion":
     # determine the newest SDK version supported both by the card and the attack
     attack_versions = SDKVersion.from_list(
         self.config["BUILD"]["versions"])
     try:
         newest = list(
             set(attack_versions).intersection(set(self.card.sdks)))[-1]
     except IndexError:
         newest = attack_versions[0]
         log.warning("Could not determine SDK Version, defaulting to '%s'",
                     str(newest))
     return newest
Exemplo n.º 5
0
 def test_from_list(self, raw_list: str, versions: list):
     assert SDKVersion.from_list(raw_list) == versions