def test_set_version_valid_input_overwrites_version(): """ It is possible to overwrite the initially set version. """ metadata = MetaData(version="0.8.1.5") metadata.set_version("4.7.1.1") assert metadata.version == "4.7.1.1"
def test_set_version_invalid_input_raises_validation_error(): """ If something not interpretable as valid version string is passed to set_version, a ValidationError is raised. """ metadata = MetaData(version="0.8.1.5") with pytest.raises(exceptions.ValidationError): metadata.set_version("this is not a valid version string")
def test_sanitize_too_short_version_will_be_filled_with_zeros(): """ PyInstaller expects a version with exactly 4 places. If a shorter version is given, the lower parts will be filled with zeros. """ metadata = MetaData(version="1.2") metadata.sanitize() assert metadata.version == "1.2.0.0"
def test_sanitize_trailing_whitespace_gets_stripped(attribute, value): """ Trailing whitespace in any parameter will be eliminated. """ metadata = MetaData() setattr(metadata, attribute, value) metadata.sanitize() assert getattr(metadata, attribute) == value.strip()
def test_sanitize_correct_values_are_not_altered(attribute): """ Values which are already good to use remain untouched. """ metadata = MetaData(**VALID_METADATA) metadata.sanitize() assert ( getattr(metadata, attribute) == VALID_METADATA[attribute] ) # check if value is still the same as in the dictionary passed to the constructor
def test_validate_invalid_values_raise_validation_error(attr, value): """ If an invalid value is given, an ValidationError must be raised. """ metadata = MetaData(**VALID_METADATA) setattr(metadata, attr, value) with pytest.raises(exceptions.ValidationError): metadata.validate()
def test_load_extra_parameters_are_ignored(): """ Any extra parameters given in the YAML file shall be silently ignored. """ testfile = TEST_DATA / "metadata_with_additional_information.yml" metadata = MetaData.from_file(testfile) assert not hasattr(metadata, "additional")
def test_load_no_mapping_raises_inputerror(): """ Loading a file which is not a valid YAML file shall raise an UsageError. """ testfile = TEST_DATA / "not_a_mapping.yml" with pytest.raises(exceptions.InputError): _ = MetaData.from_file(testfile)
def test_load_incomplete_file_raises_input_error(): """ Loading an incomplete file (cut short at the end) shall raise an InputError. """ testfile = TEST_DATA / "cut_short_metadata.yml" with pytest.raises(exceptions.InputError): _ = MetaData.from_file(testfile)
def test_load_valid_file(attribute, expected_value): """ Loading a valid and complete file should succeed and the values should be returned correctly by the to_dict method. """ testfile = TEST_DATA / "acceptancetest_metadata.yml" metadata = MetaData.from_file(testfile) assert getattr(metadata, attribute) == expected_value
def test_load_file_does_not_exist_raises_input_error(): """ If the specified file does not exist, an InputError shall be raised. """ testfile = TEST_DATA / "does_not_exist.yml" with pytest.raises(exceptions.InputError): _ = MetaData.from_file(testfile)
def test_load_directory_passed_raises_usageerror(): """ If a directory name instead of a filename is given, an UsageError shall be raised. """ testfile = TEST_DATA with pytest.raises(exceptions.InputError): _ = MetaData.from_file(testfile)
def create_versionfile( output_file, version=None, company_name=None, file_description=None, internal_name=None, legal_copyright=None, original_filename=None, product_name=None, ): # pylint: disable=too-many-arguments """ Create a new versionfile from the information given. All parameters except output_file are optional and will be replaced with placeholder values if not specified. """ metadata = MetaData( version=version, company_name=company_name, file_description=file_description, internal_name=internal_name, legal_copyright=legal_copyright, original_filename=original_filename, product_name=product_name, ) __create(metadata, output_file)
def test_load_external_version_from_file(): """ The 'Version' parameter can specify a filename instead of a version string. This filepath is seen as relative to the metadata file. In this case the version must be read from the file provided. """ testfile = TEST_DATA / "metadata_reference_to_other_file.yml" metadata = MetaData.from_file(testfile) assert metadata.version == "4.5.6.7"
def test_from_file_missing_parameters_are_given_default_values( attribute, expected_value): """ It is OK to leave out any parameter in the YAML file. In this case, an (empty) default value will be set. """ testfile = TEST_DATA / "empty_metadata.yml" metadata = MetaData.from_file(testfile) assert getattr(metadata, attribute) == expected_value
def create_versionfile_from_input_file(output_file, input_file, version=None): """ Create a new versionfile from metadata specified in input_file. If the version argument is set, the version specified in input_file will be overwritten with the value of version. """ metadata = MetaData.from_file(input_file) if version: metadata.set_version(version) __create(metadata, output_file)
def test_direct_creation(attribute): data = VALID_METADATA metadata = MetaData(**data) assert getattr(metadata, attribute) == data[attribute]
def test_validate_all_parameters_ok(): """ If all parameters are valid than the validation should simply return. """ metadata = MetaData(**VALID_METADATA) metadata.validate()