Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def should_convert_wav(profile: Dict[str, Any], wav_io: BinaryIO) -> bool:
expected_rate = int(pydash.get(profile, "audio.format.sample-rate-hertz", 16000))
expected_width = int(pydash.get(profile, "audio.format.sample-width-bits", 16)) // 8
expected_channels = int(pydash.get(profile, "audio.format.channel-count", 1))
with wave.open(wav_io, "rb") as wav_file:
rate, width, channels = (
wav_file.getframerate(),
wav_file.getsampwidth(),
wav_file.getnchannels(),
)
return (
(rate != expected_rate)
or (width != expected_width)
or (channels != expected_channels)
)
def test_chaining_commit():
chain = _.chain([1, 2, 3, 4]).power(2).sum()
committed = chain.commit()
assert chain is not committed
assert chain.value() == committed.value()
def test_cast_list(test_list, test_str):
assert ps.is_list(test_list)
assert ps.is_list(util.cast_list(test_list))
assert not ps.is_list(test_str)
assert ps.is_list(util.cast_list(test_str))
def test_cast_list(test_list, test_str):
assert ps.is_list(test_list)
assert ps.is_list(util.cast_list(test_list))
assert not ps.is_list(test_str)
assert ps.is_list(util.cast_list(test_str))
def run_trial_test_dist(spec_file, spec_name=False):
spec = spec_util.get(spec_file, spec_name)
spec = spec_util.override_test_spec(spec)
info_space = InfoSpace()
info_space.tick('trial')
spec['meta']['distributed'] = True
spec['meta']['max_session'] = 2
trial = Trial(spec, info_space)
# manually run the logic to obtain global nets for testing to ensure global net gets updated
global_nets = trial.init_global_nets()
# only test first network
if ps.is_list(global_nets): # multiagent only test first
net = list(global_nets[0].values())[0]
else:
net = list(global_nets.values())[0]
session_datas = trial.parallelize_sessions(global_nets)
trial.session_data_dict = {data.index[0]: data for data in session_datas}
trial_data = analysis.analyze_trial(trial)
trial.close()
assert isinstance(trial_data, pd.DataFrame)
def test_is_empty(case, expected):
assert _.is_empty(case) == expected
def test_property_(case, arg, expected):
assert _.map_(arg, _.property_(case)) == expected
def test_partial_as_iteratee():
func = _.partial(lambda offset, value, *args: value + offset, 5)
case = [1, 2, 3]
expected = [6, 7, 8]
_.map_(case, func) == expected
def test_map_(case, expected, sort_results):
actual = _.map_(*case)
if sort_results:
actual = sorted(actual)
assert actual == expected
def test_annotated_iteratee():
assert _.map_([1, 2], typed_function) == [2, 3]