Skip to content

Commit

Permalink
Merge pull request #261 from jeanslack/bugfix
Browse files Browse the repository at this point in the history
fix ValueError passing N/A string
  • Loading branch information
jeanslack authored Feb 7, 2024
2 parents 320fb7b + a11390f commit 2eee314
Show file tree
Hide file tree
Showing 18 changed files with 218 additions and 167 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@ License: GPL3

Change Log:

+------------------------------------+
Tue, 07 Feb 2024 V.5.0.5

* Fixed `ValueError: could not convert string to float: 'N/A'` given by the
`get_milliseconds()` function.
* The `get_milliseconds` and `get_seconds` functions have been replaced by
the `time_to_integer()` function.
* [Still Image Maker] Improved duration setting, millisecond values will be
rounded to time second values.
* Replace `milliseconds2clock` and `milliseconds2clocksec` to
new `integer_to_time` function.


+------------------------------------+
Wed, 24 Jan 2024 V.5.0.4

Expand Down
1 change: 0 additions & 1 deletion TODO
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
URGENCY: to do soon
--------------------


--------------
URGENCY: high
--------------
Expand Down
13 changes: 13 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
videomass (5.0.5-1) UNRELEASED; urgency=medium

* Fixed `ValueError: could not convert string to float: 'N/A'` given by the
`get_milliseconds()` function.
* The `get_milliseconds` and `get_seconds` functions have been replaced by
the `time_to_integer()` function.
* [Still Image Maker] Improved duration setting, millisecond values will be
rounded to time second values.
* Replace `milliseconds2clock` and `milliseconds2clocksec` to
new `integer_to_time` function.

-- Gianluca Pernigotto <[email protected]> Wed, 07 Feb 2024 11:30:00 +0200

videomass (5.0.4-1) UNRELEASED; urgency=high

* [Preset Manager] Fixed a serious issue during the automatic update task to
Expand Down
76 changes: 48 additions & 28 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: UTF-8 -*-

# Porpose: Contains test cases for the utils.py object.
# Rev: April.06.2020 *PEP8 compatible*
# Rev: 07.Feb.2024

import sys
import os.path
Expand All @@ -11,7 +11,11 @@
sys.path.insert(0, os.path.dirname(os.path.dirname(PATH)))

try:
from videomass.vdms_utils import utils
from videomass.vdms_utils.utils import (format_bytes,
to_bytes,
time_to_integer,
integer_to_time,
)
except ImportError as error:
sys.exit(error)

Expand All @@ -20,63 +24,79 @@ class TestFormatBytes(unittest.TestCase):
"""Test case for the format_bytes function."""

def test_format_bytes_bytes(self):
self.assertEqual(utils.format_bytes(518.00), "518.00B")
self.assertEqual(format_bytes(518.00), "518.00B")

def test_format_bytes_kilobytes(self):
self.assertEqual(utils.format_bytes(1024.00), "1.00KiB")
self.assertEqual(format_bytes(1024.00), "1.00KiB")

def test_format_bytes_megabytes(self):
self.assertEqual(utils.format_bytes(1048576.00), "1.00MiB")
self.assertEqual(format_bytes(1048576.00), "1.00MiB")

def test_format_bytes_gigabytes(self):
self.assertEqual(utils.format_bytes(1073741824.00), "1.00GiB")
self.assertEqual(format_bytes(1073741824.00), "1.00GiB")

def test_format_bytes_terabytes(self):
self.assertEqual(utils.format_bytes(1099511627776.00), "1.00TiB")
self.assertEqual(format_bytes(1099511627776.00), "1.00TiB")


class TestToBytes(unittest.TestCase):
"""Test case for the to_bytes function."""

def test_to_bytes_bytes(self):
self.assertEqual(utils.to_bytes("596.00B"), 596.00)
self.assertEqual(utils.to_bytes("133.55B"), 133.55)
self.assertEqual(to_bytes("596.00B"), 596.00)
self.assertEqual(to_bytes("133.55B"), 133.55)

def test_to_bytes_kilobytes(self):
self.assertEqual(utils.to_bytes("1.00KiB"), 1024.00)
self.assertEqual(utils.to_bytes("5.55KiB"), 5683.20)
self.assertEqual(to_bytes("1.00KiB"), 1024.00)
self.assertEqual(to_bytes("5.55KiB"), 5683.20)

def test_to_bytes_megabytes(self):
self.assertEqual(utils.to_bytes("13.64MiB"), 14302576.64)
self.assertEqual(utils.to_bytes("1.00MiB"), 1048576.00)
self.assertEqual(to_bytes("13.64MiB"), 14302576.64)
self.assertEqual(to_bytes("1.00MiB"), 1048576.00)

def test_to_bytes_gigabytes(self):
self.assertEqual(utils.to_bytes("1.00GiB"), 1073741824.00)
self.assertEqual(utils.to_bytes("1.55GiB"), 1664299827.20)
self.assertEqual(to_bytes("1.00GiB"), 1073741824.00)
self.assertEqual(to_bytes("1.55GiB"), 1664299827.20)

def test_to_bytes_terabytes(self):
self.assertEqual(utils.to_bytes("1.00TiB"), 1099511627776.00)
self.assertEqual(to_bytes("1.00TiB"), 1099511627776.00)


class TestTimeSeconds(unittest.TestCase):
""" Test case for the time_seconds function"""
class Test_time_to_integer(unittest.TestCase):
""" Test case for the `time_to_integer` function"""

def test_to_seconds(self):
self.assertEqual(utils.get_seconds('00:00:00'), 0.0)
self.assertEqual(utils.get_seconds('00:00:55'), 55.0)
self.assertEqual(utils.get_seconds('00:50:23'), 3023.0)
self.assertEqual(utils.get_seconds('02:30:50'), 9050.0)
self.assertEqual(utils.get_seconds('N/A'), 0)
def test_to_get_seconds(self):
self.assertEqual(time_to_integer('N/A', sec=True), 0)
self.assertEqual(time_to_integer('00:00:00', sec=True), 0)
self.assertEqual(time_to_integer('00:00:55', sec=True), 55)
self.assertEqual(time_to_integer('00:50:23', sec=True), 3023)
self.assertEqual(time_to_integer('02:30:50', sec=True), 9050)

def test_to_get_milliseconds(self):
self.assertEqual(time_to_integer('any string', sec=False), 0)
self.assertEqual(time_to_integer('00:00:00', sec=False), 0)
self.assertEqual(time_to_integer('00:00:55.777', sec=False), 55777)
self.assertEqual(time_to_integer('00:50:23', sec=False), 3023000)
self.assertEqual(time_to_integer('02:30:50', sec=False), 9050000)

def test_assertion_errors(self):
with self.assertRaises(TypeError):
# Accepts str only not any other types
time_to_integer(160999)


class TestTimeHuman(unittest.TestCase):
""" Test case for the time_human function"""

def test_to_human(self):
self.assertEqual(utils.timehuman(round(0.0)), '00:00:00')
self.assertEqual(utils.timehuman(round(55.0)), '00:00:55')
self.assertEqual(utils.timehuman(round(3023.0)), '00:50:23')
self.assertEqual(utils.timehuman(round(9050.0)), '02:30:50')
self.assertEqual(integer_to_time(round(0.0 * 1000),
mills=False), '00:00:00')
self.assertEqual(integer_to_time(round(55.0 * 1000),
mills=False), '00:00:55')
self.assertEqual(integer_to_time(round(3023.0 * 1000),
mills=False), '00:50:23')
self.assertEqual(integer_to_time(round(9050.0 * 1000),
mills=False), '02:30:50')


def main():
Expand Down
16 changes: 8 additions & 8 deletions videomass/vdms_dialogs/Unused/time_selector_v4.0.2.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
along with Videomass. If not, see <http://www.gnu.org/licenses/>.
"""
import wx
from videomass.vdms_utils.utils import get_milliseconds
from videomass.vdms_utils.utils import milliseconds2clock
from videomass.vdms_utils.utils import time_to_integer
from videomass.vdms_utils.utils import integer_to_time
# import wx.lib.masked as masked (not work on macOSX)


Expand All @@ -42,8 +42,8 @@ def __init__(self, parent, seektxt, cuttxt, milliseconds):
in the timeline panel are reproduced exactly here.
"""
self.seek_mills = get_milliseconds(seektxt)
self.cut_mills = get_milliseconds(cuttxt)
self.seek_mills = time_to_integer(seektxt)
self.cut_mills = time_to_integer(cuttxt)
self.milliseconds = milliseconds # media total duration in ms
wx.Dialog.__init__(self, parent, -1, style=wx.DEFAULT_DIALOG_STYLE)
sizer_base = wx.BoxSizer(wx.VERTICAL)
Expand Down Expand Up @@ -213,7 +213,7 @@ def get_duration_values(self):
f'{self.duration_sec.GetValue()}.'
f'{str(self.duration_mills.GetValue()).zfill(3)}'
)
return duration, get_milliseconds(duration)
return duration, time_to_integer(duration)
# ------------------------------------------------------------------#

def get_start_values(self):
Expand All @@ -226,7 +226,7 @@ def get_start_values(self):
f'{self.start_sec.GetValue()}.'
f'{str(self.start_mills.GetValue()).zfill(3)}'
)
return start, get_milliseconds(start)
return start, time_to_integer(start)
# ------------------------------------------------------------------#

def enable_start_ctrls(self, enable=True):
Expand Down Expand Up @@ -269,7 +269,7 @@ def on_duration(self, event):

entersum = start[1] + duration[1]
if entersum > self.milliseconds:
setmax = milliseconds2clock(self.milliseconds - start[1])
setmax = integer_to_time(self.milliseconds - start[1])
h, m, s = setmax.split(':')
sec, ms = s.split('.')
self.duration_hour.SetValue(int(h))
Expand All @@ -287,7 +287,7 @@ def on_start(self, event):
entersum = start[1] + duration[1]

if entersum > self.milliseconds:
setmax = milliseconds2clock(self.milliseconds - duration[1])
setmax = integer_to_time(self.milliseconds - duration[1])
h, m, s = setmax.split(':')
sec, ms = s.split('.')
self.start_hour.SetValue(int(h))
Expand Down
10 changes: 5 additions & 5 deletions videomass/vdms_dialogs/filter_colorcorrection.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
"""
import os
import wx
from videomass.vdms_utils.utils import get_milliseconds
from videomass.vdms_utils.utils import milliseconds2clocksec
from videomass.vdms_utils.utils import time_to_integer
from videomass.vdms_utils.utils import integer_to_time
from videomass.vdms_utils.utils import clockset
from videomass.vdms_io.make_filelog import make_log_template
from videomass.vdms_threads.generic_task import FFmpegGenericTask
Expand Down Expand Up @@ -105,7 +105,7 @@ def __init__(self, parent, colorset, iconreset, **kwa):
sizertime = wx.StaticBoxSizer(stboxtime, wx.HORIZONTAL)
sizerBase.Add(sizertime, 0, wx.ALL | wx.CENTER, 5)
self.sld_time = wx.Slider(self, wx.ID_ANY,
get_milliseconds(self.clock),
time_to_integer(self.clock),
0,
1 if not self.mills else self.mills,
size=(250, -1),
Expand Down Expand Up @@ -365,7 +365,7 @@ def on_seek_time(self, event):
and sets the label with the converted value.
"""
seek = self.sld_time.GetValue()
clock = milliseconds2clocksec(seek) # to 24-hour
clock = integer_to_time(seek, False) # to 24-hour
self.txttime.SetLabel(clock) # update StaticText
if not self.btn_load.IsEnabled():
self.btn_load.Enable()
Expand All @@ -376,7 +376,7 @@ def on_load_at_time(self, event):
Reloads all images frame at a given time clock point
"""
seek = self.sld_time.GetValue()
self.clock = milliseconds2clocksec(seek) # to 24-hour
self.clock = integer_to_time(seek, False) # to 24-hour
error = self.process(self.framesrc)
if error:
wx.MessageBox(f'{error}', 'ERROR', wx.ICON_ERROR, self)
Expand Down
10 changes: 5 additions & 5 deletions videomass/vdms_dialogs/filter_crop.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
import wx.lib.colourselect as csel
from pubsub import pub
from videomass.vdms_threads.generic_task import FFmpegGenericTask
from videomass.vdms_utils.utils import get_milliseconds
from videomass.vdms_utils.utils import milliseconds2clocksec
from videomass.vdms_utils.utils import time_to_integer
from videomass.vdms_utils.utils import integer_to_time
from videomass.vdms_utils.utils import clockset
from videomass.vdms_io.make_filelog import make_log_template

Expand Down Expand Up @@ -240,7 +240,7 @@ def __init__(self, parent, *args, **kwa):
wx.HORIZONTAL)
sizerBase.Add(sizer_load, 0, wx.ALL | wx.CENTER, 5)
self.sld_time = wx.Slider(self, wx.ID_ANY,
get_milliseconds(self.clock),
time_to_integer(self.clock),
0,
1 if not self.mills else self.mills,
size=(250, -1),
Expand Down Expand Up @@ -384,7 +384,7 @@ def on_Seek(self, event):
Slider event on seek time position.
"""
seek = self.sld_time.GetValue()
clock = milliseconds2clocksec(seek) # to 24-hour
clock = integer_to_time(seek, False) # to 24-hour
self.txttime.SetLabel(clock) # update StaticText
if not self.btn_load.IsEnabled():
self.btn_load.Enable()
Expand All @@ -404,7 +404,7 @@ def make_frame_from_file(self, event):
sseg = ''
else:
seek = self.sld_time.GetValue()
self.clock = milliseconds2clocksec(seek) # to 24-HH
self.clock = integer_to_time(seek, False) # to 24-HH
sseg = f'-ss {self.clock}'

arg = (f'{sseg} -i "{self.filename}" -f image2 '
Expand Down
8 changes: 4 additions & 4 deletions videomass/vdms_dialogs/filter_scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
from videomass.vdms_io import io_tools
from videomass.vdms_dialogs.widget_utils import NormalTransientPopup
from videomass.vdms_threads.generic_task import FFmpegGenericTask
from videomass.vdms_utils.utils import get_milliseconds
from videomass.vdms_utils.utils import milliseconds2clocksec
from videomass.vdms_utils.utils import time_to_integer
from videomass.vdms_utils.utils import integer_to_time
from videomass.vdms_io.make_filelog import make_log_template


Expand Down Expand Up @@ -66,7 +66,7 @@ def __init__(self, parent, *args, **kwa):
self.filename = kwa['filename'] # selected filename on queued list
name = os.path.splitext(os.path.basename(self.filename))[0]
self.frame = os.path.join(f'{Scale.TMPSRC}', f'{name}.png') # image
self.mills = get_milliseconds(kwa['duration'].split('.')[0])
self.mills = time_to_integer(kwa['duration'].split('.')[0])

wx.Dialog.__init__(self, parent, -1, style=wx.DEFAULT_DIALOG_STYLE)
sizerBase = wx.BoxSizer(wx.VERTICAL)
Expand Down Expand Up @@ -346,7 +346,7 @@ def process(self, concat):
if not self.mills:
sseg = ''
else:
stime = milliseconds2clocksec(int(self.mills / 2))
stime = integer_to_time(int(self.mills / 2), False)
sseg = f'-ss {stime}'
scale = '' if not concat else f'-vf "{concat}"'
arg = (f'{sseg} -i "{self.filename}" -f image2 -update 1 '
Expand Down
12 changes: 6 additions & 6 deletions videomass/vdms_dialogs/filter_stab.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
import webbrowser
import wx
import wx.lib.agw.floatspin as FS
from videomass.vdms_utils.utils import get_milliseconds
from videomass.vdms_utils.utils import milliseconds2clocksec
from videomass.vdms_utils.utils import time_to_integer
from videomass.vdms_utils.utils import integer_to_time
from videomass.vdms_utils.utils import clockset
from videomass.vdms_io import io_tools
from videomass.vdms_threads.generic_task import FFmpegGenericTask
Expand Down Expand Up @@ -94,7 +94,7 @@ def __init__(self, parent, *args, **kwa):
sizertime.Add(boxtime, 0, wx.ALL | wx.CENTER, 5)

self.sld_time = wx.Slider(self, wx.ID_ANY,
get_milliseconds(self.clock),
time_to_integer(self.clock),
0,
1 if not self.mills else self.mills,
size=(250, -1),
Expand Down Expand Up @@ -451,7 +451,7 @@ def on_seek_time(self, event):
and sets the label with the converted value.
"""
seek = self.sld_time.GetValue()
clock = milliseconds2clocksec(seek) # to 24-hour
clock = integer_to_time(seek, False) # to 24-hour
self.lab_time.SetLabel(clock) # update StaticText
if not self.btn_snap.IsEnabled():
self.btn_snap.Enable()
Expand Down Expand Up @@ -513,8 +513,8 @@ def process(self, infile, outfile=None, args='', mode=None):
seek = self.mills - stime
if seek < 0:
seek, stime = 0, self.mills
duration = milliseconds2clocksec(stime) # to 24-hour
self.clock = milliseconds2clocksec(seek) # to 24-hour
duration = integer_to_time(stime, False) # to 24-hour
self.clock = integer_to_time(seek, False) # to 24-hour
sseg = f'-ss {self.clock} -t {duration}'

if mode == 'detect':
Expand Down
Loading

0 comments on commit 2eee314

Please sign in to comment.