def test_bad_mime_types_config(bad_mime_types_enrichments_config): with pytest.raises(schema.SchemaError) as excinfo: config.parse(bad_mime_types_enrichments_config) assert ( "One of the accepted_input_mime_types you defined is not supported as input." in str(excinfo.value) )
def test_valid_config_optional(valid_config_with_optional): parsed_config = config.parse(valid_config_with_optional) assert parsed_config.get("normalization_headroom") == 0.2 valid_config_with_optional.pop("normalization_headroom") parsed_config = config.parse(valid_config_with_optional) assert parsed_config.get("normalization_headroom", {}) == 0.1
def harmonize_directory( audio_input_dir, audio_output_dir, conf, json_output_dir, image_output_dir, logger=None, ): if json_output_dir is None: json_output_dir = audio_output_dir if image_output_dir is None: image_output_dir = audio_output_dir with open(conf, "r") as f: try: raw_config = yaml.load(f, Loader=yaml.FullLoader) except yaml.YAMLError as exc: logger.error( "Cannot read your YAML config. File does not seems valid: ", exc) sys.exit(1) try: parsed_config = config.parse(raw_config) except schema.SchemaError as e: for error in e.errors: if error is not None: logger.error(error) logger.error( "Could not parse the config, it does not have the expected schema." ) sys.exit(1) valid_extensions = [ "*." + m.replace("audio/", "") for m in parsed_config.get( "validations", {}).get("accepted_input_mime_types", []) ] globs = [os.path.join(audio_input_dir, ext) for ext in valid_extensions] for file_type in globs: for f in glob(file_type): start_time = time.time() results = harmonize_file(f, audio_output_dir, json_output_dir, image_output_dir, parsed_config) process_time = time.time() - start_time f = os.path.basename(f) if len(results["validation_errors"]) > 0: logger.warning( f"Validation error for {f}: {results['validation_errors']}" ) logger.info( f"Successfully processed file {f} in {int(process_time)} seconds." )
def test_wrong_optional( normalization_headroom_bad_type, normalization_headroom_too_high, normalization_headroom_bad_float, ): expected_error = "Normalization headroom should be between 0.1 and 0.9 with a single digit decimal." with pytest.raises(schema.SchemaError) as excinfo: config.parse(normalization_headroom_bad_type) assert expected_error in str(excinfo.value) with pytest.raises(schema.SchemaError) as excinfo: config.parse(normalization_headroom_too_high) assert expected_error in str(excinfo.value) with pytest.raises(schema.SchemaError) as excinfo: config.parse(normalization_headroom_bad_float) assert expected_error in str(excinfo.value)
def test_invalid_min_bitrate(invalid_min_max_bitrate): with pytest.raises(schema.SchemaError) as excinfo: config.parse(invalid_min_max_bitrate) assert "The minimum_input_bitrate is not 320, 192 or 128" in str(excinfo.value)
def test_unexisting_validation_config(unexisting_validation_config): with pytest.raises(schema.SchemaError) as excinfo: config.parse(unexisting_validation_config) assert "Wrong key 'mandatory_togs'" in str(excinfo.value)
def test_missing_mandatory_config(missing_mandatory_config): with pytest.raises(schema.SchemaError) as excinfo: config.parse(missing_mandatory_config) assert "Missing key: 'output_bitrate'" in str(excinfo.value)
def test_bad_required_enrichments_config(bad_required_enrichments_config): with pytest.raises(schema.SchemaError) as excinfo: config.parse(bad_required_enrichments_config) assert "This required enrichment is not supported" in str(excinfo.value)
def test_bad_bitrate_config(bad_bitrate_config): with pytest.raises(schema.SchemaError) as excinfo: config.parse(bad_bitrate_config) assert "Output bit rate must be 128, 192 or 320" in str(excinfo.value)
def test_valid_config(valid_config): parsed_config = config.parse(valid_config) assert isinstance(parsed_config, dict) assert parsed_config.get("normalization_headroom") == 0.1