def test_zip(out_file, test_file): assert not out_file.exists() with Miz(test_file) as miz: miz.zip(out_file) assert out_file.exists() with Miz(out_file) as miz2: assert miz.mission.d == miz2.mission.d miz.mission.weather.cloud_density = 4 assert not miz.mission.d == miz2.mission.d
def test_sortie_name(test_file, out_file): with Miz(test_file) as miz: assert miz.mission.sortie_name == 'sortie_test' wrong_sortie_names = [1, 0, -1, True, None] for wrong_sortie_name in wrong_sortie_names: with pytest.raises(ValueError): miz.mission.sortie_name = wrong_sortie_name miz.mission.sortie_name = 'caribou' assert miz.mission.sortie_name == 'caribou' miz.zip(out_file) with Miz(out_file) as miz: assert miz.mission.sortie_name == 'caribou'
def test_set_hidden(test_file, out_file): with Miz(test_file) as miz: group = miz.mission.get_group_by_name('etcher') assert isinstance(group, Group) assert not group.group_hidden group.group_hidden = True assert group.group_hidden miz.zip(out_file) with Miz(out_file) as miz: new_group = miz.mission.get_group_by_name('etcher') assert isinstance(new_group, Group) for attrib in [x for x in Group.attribs if not x == 'group_hidden']: assert getattr(group, attrib) == getattr(new_group, attrib) assert group.group_hidden
def test_objects(all_objects): with Miz(all_objects) as miz: _ = miz.mission._blue_coa.get_country_by_id(2) country = miz.mission._blue_coa.get_country_by_id(2) assert isinstance(country, Country) assert country.groups assert country.units for category in ('helicopter', 'ship', 'vehicle', 'plane'): assert country.get_groups_from_category(category) assert country.get_units_from_category(category) for group in country.get_groups_from_category(category): assert isinstance(group, Group) for unit in country.get_units_from_category(category): assert isinstance(unit, BaseUnit) for wrong_category in (True, -1, 0, 1, False, None, 'caribou'): with pytest.raises(ValueError, message=wrong_category): for _ in country.get_groups_from_category(wrong_category): pass with pytest.raises(ValueError, message=wrong_category): for _ in country.get_units_from_category(wrong_category): pass for id_ in (1, 2, 3, 4): assert isinstance(country.get_group_by_id(id_), Group) assert isinstance(country.get_unit_by_id(id_), BaseUnit) assert country.get_unit_by_id(5) is None assert country.get_group_by_id(5) is None for group_name in ('New Vehicle Group', 'New Helicopter Group', 'New Airplane Group', 'New Ship Group'): assert isinstance(country.get_group_by_name(group_name), Group) assert country.get_group_by_name('some other group') is None for unit_name in ('Unit #1', 'Unit #001', 'Pilot #001', 'Pilot #002'): assert isinstance(country.get_unit_by_name(unit_name), BaseUnit) assert country.get_unit_by_name('some other unit') is None
def test_temp_dir_cleaning(test_file): mis = Miz(test_file) mis.unzip() assert mis.temp_dir.exists() assert mis.temp_dir.glob('*') mis._remove_temp_dir() assert not mis.temp_dir.exists()
def test_get_country(mission, test_file): assert isinstance(mission.blue_coa.get_country_by_id(2), Country) assert isinstance(mission.blue_coa.get_country_by_name('USA'), Country) with pytest.raises(ValueError): mission.red_coa.get_country_by_name('USA') with pytest.raises(ValueError): mission.red_coa.get_country_by_id(2) with Miz(test_file) as miz: assert isinstance(miz.mission._blue_coa.get_country_by_name('USA'), Country)
def test_large_zip(large_file): with Miz(large_file, keep_temp_dir=True) as miz: out_file = miz.zip() assert Path(out_file).exists() try: with Miz(out_file) as miz2: assert miz.mission.d == miz2.mission.d miz.mission.weather.cloud_density = 4 assert not miz.mission.d == miz2.mission.d sleep(1) m1 = miz.mission_file m2 = miz2.mission_file with open(m1, encoding=ENCODING) as _f: t1 = _f.read() with open(m2, encoding=ENCODING) as _f: t2 = _f.read() assert t1 == t2 finally: Path(out_file).unlink()
def test_group_start_time(test_file, out_file): with Miz(test_file) as miz: group = miz.mission.get_group_by_name('etcher') assert miz.mission.mission_start_time == group.group_start_time assert miz.mission.mission_start_datetime_as_string == group.group_start_date_time_as_string assert group.group_start_date_time_as_string == '01/06/2011 12:00:00' assert group.group_start_delay == 0 group.group_start_delay += 60 assert group.group_start_date_time_as_string == '01/06/2011 12:01:00' group.group_start_delay += 3600 assert group.group_start_date_time_as_string == '01/06/2011 13:01:00' group.group_start_delay = 0 group.group_start_delay = 3600 assert group.group_start_date_time_as_string == '01/06/2011 13:00:00' miz.zip(out_file) with Miz(out_file) as miz: group = miz.mission.get_group_by_name('etcher') assert group.group_start_delay == 3600
def test_get_groups_from_category(mission, all_objects): for invalid_category in ('caribou', 'Plane', 'plAne', 'ships', -1, 0, 1, True, False, None): with pytest.raises(ValueError): for _ in mission.blue_coa.get_groups_from_category( invalid_category): pass with Miz(all_objects) as miz: for category in ('ship', 'plane', 'helicopter', 'vehicle'): value = 0 for group in miz.mission._blue_coa.get_groups_from_category( category): assert isinstance(group, Group) assert group.group_category == category value += 1 assert value == 1
def test_apply_to_miz(test_file, example_datetime): result_miz = './test.miz' example_datetime = example_datetime.replace(tzinfo=None, microsecond=0) if example_datetime.day == 31: example_datetime = example_datetime.replace(day=30) year = example_datetime.year month = example_datetime.month day = example_datetime.day hour = example_datetime.hour minute = example_datetime.minute second = example_datetime.second input_string = f'{year:04d}{month:02d}{day:02d}{hour:02d}{minute:02d}{second:02d}' time = MissionTime.from_string(input_string) time.apply_to_miz(test_file, result_miz, overwrite=True) with Miz(result_miz) as miz: # original_start_time = miz.mission.mission_start_time # assert miz.mission.mission_start_time != original_start_time assert time.day == miz.mission.day assert time.month == miz.mission.month assert time.year == miz.mission.year assert time.mission_start_time == miz.mission.mission_start_time
def test_bad_zip_file(bad_zip_file): from zipfile import BadZipFile mis = Miz(bad_zip_file) with pytest.raises(BadZipFile): mis.unzip()
def test_missing_file_in_miz(missing_file): missing = Miz(missing_file) with pytest.raises(FileNotFoundError): missing.unzip()
def test_is_unzipped(test_file): mis = Miz(test_file) assert not mis.zip_content mis.unzip() assert mis.zip_content
def test_decode(test_file): miz = Miz(test_file) miz.unzip() miz.decode()
def test_unzip(test_file): miz = Miz(test_file) miz.unzip()
def test_context(test_file): with Miz(test_file) as miz: assert isinstance(miz.mission, Mission) assert isinstance(miz.l10n, dict) assert miz.zip_content
def test_init(test_file): Miz(test_file) with pytest.raises(FileNotFoundError): Miz('./i_do_not_exist')
def test_large_decode(large_file): miz = Miz(large_file) miz.unzip() miz.decode()
def test_next_unit_id(mission, duplicate_group_id): assert mission.next_unit_id == 42 with pytest.raises(IndexError): with Miz(duplicate_group_id) as miz: assert miz.mission.next_unit_id