Skip to content

Commit

Permalink
bugfix: stat presenter now displays files sizes accurately in MB
Browse files Browse the repository at this point in the history
  • Loading branch information
roryai committed Jan 6, 2024
1 parent e017819 commit 14281bb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion app/stat_presenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def __file_or_files(self, count):
def __size_calc(self, sum_size):
if sum_size is None:
return 0.0
return round(sum_size / 1024, 2)
return round(sum_size / 1048576, 2)

def __single_or_plural_grammar(self, count, single_statement, plural_statement):
if count == 1:
Expand Down
28 changes: 14 additions & 14 deletions test/test_stat_presenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
from .helpers import *


simple_file_1 = File('source', 'destination', 1024, name_clash=False)
simple_file_2 = File('source', 'destination', 32768, name_clash=False)
duplicate_file_1 = File('source', '', 2048, name_clash=False)
duplicate_file_2 = File('source', '', 8192, name_clash=False)
name_clash_file_1 = File('source', 'destination', 16384, name_clash=True)
name_clash_file_2 = File('source', 'destination', 4096, name_clash=True)
simple_file_1 = File('source', 'destination', 102400, name_clash=False)
simple_file_2 = File('source', 'destination', 3276800, name_clash=False)
duplicate_file_1 = File('source', '', 204800, name_clash=False)
duplicate_file_2 = File('source', '', 819200, name_clash=False)
name_clash_file_1 = File('source', 'destination', 1638400, name_clash=True)
name_clash_file_2 = File('source', 'destination', 409600, name_clash=True)


@pytest.fixture(autouse=True)
Expand All @@ -24,13 +24,13 @@ def test_plural_grammar_for_all_file_categories(capsys):
Destination directory: destination/
6 candidate files discovered in source directory.
Total size of candidate files: 63.0MB
Total size of candidate files: 6.15MB
2 files are duplicates and will not be copied.
2 files have name clashes and will be copied with a unique suffix.
4 files will be copied.
Total size of files to be copied: 53.0MB\n"""
Total size of files to be copied: 5.18MB\n"""
for f in [simple_file_1, simple_file_2, duplicate_file_1, duplicate_file_2, name_clash_file_1, name_clash_file_2]:
insert_db_record(f)
StatPresenter().present_analysis_of_candidate_files('source/', 'destination/')
Expand All @@ -44,13 +44,13 @@ def test_singular_grammar_for_duplicate_and_name_clash_files(capsys):
Destination directory: destination/
2 candidate files discovered in source directory.
Total size of candidate files: 18.0MB
Total size of candidate files: 1.76MB
1 file is a duplicate and will not be copied.
1 file has a name clash and will be copied with a unique suffix.
1 file will be copied.
Total size of file to be copied: 16.0MB\n"""
Total size of file to be copied: 1.56MB\n"""
for f in [duplicate_file_1, name_clash_file_1]:
insert_db_record(f)
StatPresenter().present_analysis_of_candidate_files('source/', 'destination/')
Expand All @@ -64,10 +64,10 @@ def test_singular_grammar_for_candidate_files_and_files_to_be_copied(capsys):
Destination directory: destination/
1 candidate file discovered in source directory.
Total size of candidate file: 1.0MB
Total size of candidate file: 0.1MB
1 file will be copied.
Total size of file to be copied: 1.0MB\n"""
Total size of file to be copied: 0.1MB\n"""
insert_db_record(simple_file_1)
StatPresenter().present_analysis_of_candidate_files('source/', 'destination/')
captured = capsys.readouterr()
Expand All @@ -80,10 +80,10 @@ def test_does_not_display_name_clash_or_duplicate_info_when_no_files_in_these_ca
Destination directory: destination/
2 candidate files discovered in source directory.
Total size of candidate files: 33.0MB
Total size of candidate files: 3.22MB
2 files will be copied.
Total size of files to be copied: 33.0MB\n"""
Total size of files to be copied: 3.22MB\n"""
for f in [simple_file_1, simple_file_2]:
insert_db_record(f)
StatPresenter().present_analysis_of_candidate_files('source/', 'destination/')
Expand Down

0 comments on commit 14281bb

Please sign in to comment.