[pitivi] render: Avoid showing 0 MB estimated size
- From: Alexandru Băluț <alexbalut src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pitivi] render: Avoid showing 0 MB estimated size
- Date: Fri, 2 Jul 2021 22:27:53 +0000 (UTC)
commit 1823179e5d0d16c62a0ceb81b3f6d766876d9b37
Author: garggaurangi <ggarg276 gmail com>
Date: Thu Mar 25 23:58:15 2021 +0530
render: Avoid showing 0 MB estimated size
Fixes #2522
pitivi/render.py | 19 ++++++++++---------
tests/test_render.py | 10 ++++++++++
2 files changed, 20 insertions(+), 9 deletions(-)
---
diff --git a/pitivi/render.py b/pitivi/render.py
index 3170ca5f2..5e58116f6 100644
--- a/pitivi/render.py
+++ b/pitivi/render.py
@@ -1163,18 +1163,19 @@ class RenderDialog(Loggable):
current_filesize = os.stat(path_from_uri(self.outfile)).st_size
length = self.project.ges_timeline.props.duration
- estimated_size = float(
- current_filesize * float(length) / self.current_position)
+ estimated_size = current_filesize * length / self.current_position
# Now let's make it human-readable (instead of octets).
# If it's in the giga range (10⁹) instead of mega (10⁶), use 2 decimals
- if estimated_size > 10e8:
- gigabytes = estimated_size / (10 ** 9)
+ gigabytes = estimated_size / (10 ** 9)
+ if gigabytes >= 1:
return _("%.2f GB") % gigabytes
- else:
- megabytes = int(estimated_size / (10 ** 6))
- if megabytes > 30:
- megabytes = int(round(megabytes, -1)) # -1 means round to 10
- return _("%d MB") % megabytes
+
+ megabytes = int(estimated_size / (10 ** 6))
+ if megabytes == 0:
+ return None
+ elif megabytes > 30:
+ megabytes = int(round(megabytes, -1)) # -1 means round to 10
+ return _("%d MB") % megabytes
def _update_filename(self, basename):
"""Updates the filename UI element to show the specified file name."""
diff --git a/tests/test_render.py b/tests/test_render.py
index 2c2d274ef..55ae710d0 100644
--- a/tests/test_render.py
+++ b/tests/test_render.py
@@ -653,3 +653,13 @@ class TestRender(BaseTestMediaLibrary):
# The audio rate is changed because the default render preset
# has an audio encoder which does not support 44100.
self.assertEqual(project.audiorate, 48000)
+
+ def test__get_filesize_estimate(self):
+ project = self.create_simple_project()
+ dialog = self.create_rendering_dialog(project)
+ dialog.current_position = 1
+ from pitivi import render
+ with mock.patch.object(render, "path_from_uri"):
+ with mock.patch("pitivi.render.os.stat") as os_stat:
+ os_stat.return_value.st_size = 0
+ self.assertIsNone(dialog._get_filesize_estimate())
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]