write tests for SoundStat

This commit is contained in:
bkfox
2023-06-26 13:44:24 +02:00
parent b2f4bce717
commit 8fcfdcc74f
5 changed files with 65 additions and 47 deletions

View File

@@ -73,19 +73,18 @@ class SoundStats:
def __init__(self, path, sample_length=None):
self.path = path
self.sample_length = (
sample_length if sample_length is not None else self.sample_length
)
if sample_length is not None:
self.sample_length = sample_length
def get_file_stats(self):
return self.stats and self.stats[0]
return self.stats and self.stats[0] or None
def analyse(self):
logger.debug("complete file analysis")
self.stats = [SoxStats(self.path)]
position = 0
length = self.stats[0].get("length")
print(self.stats, "-----")
if not self.sample_length:
return
@@ -109,23 +108,23 @@ class SoundStats:
self.resume()
def resume(self):
def view(array):
return [
"file"
if index == 0
else "sample {} (at {} seconds)".format(
index, (index - 1) * self.sample_length
)
for index in array
]
if self.good:
logger.debug(
self.path + " -> good: \033[92m%s\033[0m",
", ".join(view(self.good)),
", ".join(self._view(self.good)),
)
if self.bad:
logger.debug(
self.path + " -> bad: \033[91m%s\033[0m",
", ".join(view(self.bad)),
", ".join(self._view(self.bad)),
)
def _view(self, array):
return [
"file"
if index == 0
else "sample {} (at {} seconds)".format(
index, (index - 1) * self.sample_length
)
for index in array
]