Esempio n. 1
0
def test_radios_generator(radio_file):
    with Miz(radio_file) as miz:
        unit = miz.mission.get_unit_by_id(6)
        # noinspection PyUnusedLocal
        for radio in unit.radio_presets:
            # TODO resume
            pass
Esempio n. 2
0
def test_l10n_dict(test_file):
    m = Miz(test_file)
    with pytest.raises(RuntimeError):
        assert m.l10n
    m.unzip()
    m.decode()
    assert isinstance(m.l10n, dict)
Esempio n. 3
0
def test_map_resources(test_file):
    m = Miz(test_file)
    with pytest.raises(RuntimeError):
        assert m.map_res
    m.unzip()
    m.decode()
    assert isinstance(m.map_res, dict)
Esempio n. 4
0
def test_mission_dict(test_file):
    m = Miz(test_file)
    with pytest.raises(RuntimeError):
        assert m.mission
    m.unzip()
    m.decode()
    assert isinstance(m.mission, Mission)
Esempio n. 5
0
def test_radios_set_freq(radio_file, out_file):
    with Miz(radio_file) as miz:
        unit = miz.mission.get_unit_by_id(1)
        assert isinstance(unit, FlyingUnit)
        radio = unit.get_radio_by_number(1)
        radio.set_frequency(1, radio.min)
        radio.set_frequency(1, radio.max)
        for wrong_freq_type in [None, False, True, 'caribou', 0, -1]:
            with pytest.raises(ValueError):
                radio.set_frequency(1, wrong_freq_type)
        for wrong_freq in [radio.max + 1, radio.min - 1]:
            with pytest.raises(ValueError):
                radio.set_frequency(1, wrong_freq)
        miz.zip(out_file)
        with Miz(out_file) as miz2:
            unit2 = miz2.mission.get_unit_by_id(1)
            assert isinstance(unit2, FlyingUnit)
            radio2 = unit2.get_radio_by_number(1)
            assert type(radio) == type(radio2)
Esempio n. 6
0
def test_radios_equal(radio_file):
    with Miz(radio_file) as miz:
        unit = miz.mission.get_unit_by_id(6)
        assert isinstance(unit, FlyingUnit)
        radio1 = unit.get_radio_by_number(1)
        radio2 = unit.get_radio_by_number(2)
        assert not radio1 == radio2
        radio3 = miz.mission.get_unit_by_id(7).get_radio_by_number(2)
        assert radio1.radio_name == radio3.radio_name
        assert radio1 == radio3
        radio1.set_frequency(1, 30.0)
        assert not radio1 == radio3
Esempio n. 7
0
def test_radios(unit_id, unit_type, radios_to_test, radio_file):
    with Miz(radio_file) as miz:
        mission = miz.mission

    unit = mission.get_unit_by_id(unit_id)
    assert unit.unit_type == unit_type
    assert isinstance(unit, FlyingUnit)
    for radio in radios_to_test:
        radio_name, radio_number, channels_to_test = radio
        radio_by_name = unit.get_radio_by_name(radio_name)
        radio_by_number = unit.get_radio_by_number(radio_number)
        assert radio_by_name == radio_by_number
        for channel, freq in channels_to_test.items():
            assert radio_by_name.get_frequency(channel) == freq
            assert radio_by_number.get_frequency(channel) == freq
Esempio n. 8
0
    def from_miz(miz_file_path: str) -> 'MissionTime':
        """
        Creates a MissionTime object from a MIZ file

        :param miz_file_path: path to the source MIZ file
        :type miz_file_path: str
        :return: MissionTime object
        :rtype: MissionTime
        """
        _miz_file_path = Path(miz_file_path).absolute()
        if not _miz_file_path.exists():
            raise MizFileNotFoundError(str(_miz_file_path))
        with Miz(str(_miz_file_path)) as miz:
            _year = miz.mission.year
            _month = miz.mission.month
            _day = miz.mission.day
            _minute, _second = divmod(miz.mission.mission_start_time, 60)
            _hour, _minute = divmod(_minute, 60)
        return MissionTime(_year, _month, _day, _hour, _minute, _second)
Esempio n. 9
0
    def apply_to_miz(self, source_miz_file: str, out_miz_file: str, overwrite: bool = False) -> None:
        """
        Applies this MissionTime to a MIZ file

        :param source_miz_file: path to the source MIZ file
        :type source_miz_file: str
        :param out_miz_file: path to the target MIZ file
        :type out_miz_file: str
        :param overwrite: whether or not to overwrite an existing target file
        :type overwrite: bool
        """
        _source_miz_file_path = Path(source_miz_file).absolute()
        _out_miz_file_path = Path(out_miz_file).absolute()
        if not _source_miz_file_path.exists():
            raise MizFileNotFoundError(str(_source_miz_file_path))
        if _out_miz_file_path.exists() and not overwrite:
            raise MizFileAlreadyExistsError(str(_out_miz_file_path))
        with Miz(str(_source_miz_file_path)) as miz:
            LOGGER.debug('applying time to miz: %s', self.iso_format)
            miz.mission.day = self.day
            miz.mission.month = self.month
            miz.mission.year = self.year
            miz.mission.mission_start_time = self.mission_start_time
            miz.zip(str(_out_miz_file_path))
Esempio n. 10
0
def test_fog(dust_miz_file):
    with Miz(dust_miz_file) as miz:
        assert miz.mission.weather.dust_enabled is True
        assert miz.mission.weather.dust_density == 2233
        assert miz.mission.theatre == 'PersianGulf'
Esempio n. 11
0
def test_context(test_file):
    with Miz(test_file) as miz:
        assert isinstance(miz.mission, Mission)
        tmpdir = os.path.abspath(miz.temp_dir)

    assert not os.path.exists(tmpdir)
Esempio n. 12
0
def test_resources(test_file):
    m = Miz(test_file)
    assert isinstance(m.resources, set)
    assert not m.resources
Esempio n. 13
0
def test_unzip(test_file):
    m = Miz(test_file)
    m.unzip()
Esempio n. 14
0
# def bad_files(request):
#     yield Path(TEST_FILES_FOLDER.joinpath(request.param))


@pytest.fixture(autouse=True)
def remove_out_file():
    """Removes OUT_FILE between tests"""
    path = Path(TEST_FILES_FOLDER.joinpath('TRG_KA50_EMFT.miz'))
    if path.exists():
        path.unlink()
    yield
    if path.exists():
        path.unlink()


with Miz(Path(TEST_FILES_FOLDER.joinpath('test_158.miz'))) as miz:
    DUMMY_MISSION = miz.mission


@pytest.fixture()
def mission() -> Mission:
    yield Mission(copy.deepcopy(DUMMY_MISSION.d),
                  copy.deepcopy(DUMMY_MISSION.l10n))


# @pytest.fixture()
# def mission_dict():
#     yield copy.deepcopy(DUMMY_MISSION.d)

# @pytest.fixture()
# def mission_l10n():