Skip to content

Commit

Permalink
Merge pull request #2 from damodhar918/Pretty-print
Browse files Browse the repository at this point in the history
Testing done
  • Loading branch information
damodhar918 committed Oct 15, 2023
2 parents 906bfb3 + 1d4bbdd commit a87b533
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 58 deletions.
5 changes: 1 addition & 4 deletions sdgp/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,7 @@ def suggestion():
print(
" If you have any suggestion/question/errors ping Damodhar Jangam \
will update in next release. ",
sep=Fore.CYAN + "#\n# " + Fore.WHITE,
end='')
print(
"Doc link : https://damodhar918.github.io/sdgp/ \
"Doc link : https://damodhar918.github.io/sdgp/ \
",
sep=Fore.CYAN + "#\n# " + Fore.WHITE,
end='')
Expand Down
6 changes: 3 additions & 3 deletions sdgp/sdgp.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ def __init__(self, volume: int, file: str, conf_file: str,
self.volume = int(volume) # Number of rows to volume
self.file = file.split('.csv')[0] \
if file.strip().endswith('.csv') else file
if conf_file.strip().endswith('.csv') == file.strip().endswith('.csv'):
self.file = self.file+'_'
self.csv_file_path = file.strip() # to read CSV file path
self.start_time = time.time()
self.outputFormat = format
self.choice = choice
if conf_file:

if conf_file.strip().split('.csv')[0] == file.strip().\
split('.csv')[0]:
self.file = self.file+'_'
self.conf_file_path = conf_file.strip()
self.conf_df = self.checkFile(self.conf_file_path)
self.conf_dict = self.conf_df.to_dict(
Expand Down
88 changes: 41 additions & 47 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,15 @@ def test_main_mock_data():
with patch.object(sys, 'argv', ['sdgp', '-c', 'm', records, file_format,
mock_file_name,
conf_file]):
with patch('sys.stdout', new=io.StringIO()) as fake_output:
main()
assert f'Fetched the file {conf_file}! Time taken:' \
in fake_output.getvalue()
assert f'File has been saved as {mock_file_outfile}\
_{mode}_{records}.{file_format}! Time taken: ' in fake_output.getvalue()
if os.path.exists(f'{mock_file_outfile}\
# with patch('sys.stdout', new=io.StringIO()) as fake_output:
main()
if os.path.exists(f'{mock_file_outfile}\
_{mode}_{records}.{file_format}'):
os.remove(f'{mock_file_outfile}\
os.remove(f'{mock_file_outfile}\
_{mode}_{records}.{file_format}')
assert True
else:
assert False
assert True
else:
assert False


def test_main_mock_data_with_large_number_of_records():
Expand All @@ -43,17 +39,15 @@ def test_main_mock_data_with_large_number_of_records():
with patch.object(sys, 'argv', ['sdgp', '-c', 'm', records, file_format,
mock_file_name,
conf_file]):
with patch('sys.stdout', new=io.StringIO()) as fake_output:
main()
assert f'File has been saved as {mock_file_outfile}\
_{mode}_{records}.{file_format}! Time taken: ' in fake_output.getvalue()
if os.path.exists(f'{mock_file_outfile}\
# with patch('sys.stdout', new=io.StringIO()) as fake_output:
main()
if os.path.exists(f'{mock_file_outfile}\
_{mode}_{records}.{file_format}'):
os.remove(f'{mock_file_outfile}\
os.remove(f'{mock_file_outfile}\
_{mode}_{records}.{file_format}')
assert True
else:
assert False
assert True
else:
assert False


def test_main_mock_data_with_edit_csv_to_parquet():
Expand All @@ -67,17 +61,17 @@ def test_main_mock_data_with_edit_csv_to_parquet():
with patch.object(sys, 'argv', ['sdgp', '-c', mode, records, file_format,
mock_file_name,
conf_file]):
with patch('sys.stdout', new=io.StringIO()) as fake_output:
main()
assert f'File has been saved as {mock_file_outfile}\
_{mode}_{records}.{file_format}! Time taken: ' in fake_output.getvalue()
if os.path.exists(f'{mock_file_outfile}\
# with patch('sys.stdout', new=io.StringIO()) as fake_output:
main()
# assert f'File has been saved as {mock_file_outfile}\
# _{mode}_{records}.{file_format}! Time taken: ' in fake_output.getvalue()
if os.path.exists(f'{mock_file_outfile}\
_{mode}_{records}.{file_format}'):
os.remove(f'{mock_file_outfile}\
os.remove(f'{mock_file_outfile}\
_{mode}_{records}.{file_format}')
assert True
else:
assert False
assert True
else:
assert False


def test_main_mock_data_scale_with_duplicates():
Expand All @@ -91,17 +85,17 @@ def test_main_mock_data_scale_with_duplicates():
with patch.object(sys, 'argv', ['sdgp', '-c', mode, records, file_format,
mock_file_name,
conf_file]):
with patch('sys.stdout', new=io.StringIO()) as fake_output:
main()
assert f'File has been saved as {mock_file_outfile}\
_{mode}_{records}.{file_format}! Time taken: ' in fake_output.getvalue()
if os.path.exists(f'{mock_file_outfile}\
# with patch('sys.stdout', new=io.StringIO()) as fake_output:
main()
# assert f'File has been saved as {mock_file_outfile}\
# _{mode}_{records}.{file_format}! Time taken: ' in fake_output.getvalue()
if os.path.exists(f'{mock_file_outfile}\
_{mode}_{records}.{file_format}'):
os.remove(f'{mock_file_outfile}\
os.remove(f'{mock_file_outfile}\
_{mode}_{records}.{file_format}')
assert True
else:
assert False
assert True
else:
assert False


def test_main_mock_data_and_edit():
Expand All @@ -115,14 +109,14 @@ def test_main_mock_data_and_edit():
with patch.object(sys, 'argv', ['sdgp', '-c', mode, records, file_format,
mock_file_name,
conf_file]):
with patch('sys.stdout', new=io.StringIO()) as fake_output:
main()
assert f'File has been saved as {mock_file_outfile}\
_{mode}_{records}.{file_format}! Time taken: ' in fake_output.getvalue()
if os.path.exists(f'{mock_file_outfile}\
# with patch('sys.stdout', new=io.StringIO()) as fake_output:
main()
# assert f'File has been saved as {mock_file_outfile}\
# _{mode}_{records}.{file_format}! Time taken: ' in fake_output.getvalue()
if os.path.exists(f'{mock_file_outfile}\
_{mode}_{records}.{file_format}'):
os.remove(f'{mock_file_outfile}\
os.remove(f'{mock_file_outfile}\
_{mode}_{records}.{file_format}')
assert True
else:
assert False
assert True
else:
assert False
9 changes: 5 additions & 4 deletions tests/test_sdgp.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,9 @@ def test_clock(self):
end_time = time.time()
# Check if the clock property returns a string that reflects
# the execution time
expected_clock = f"; Time taken: \
{time.strftime('%X', time.gmtime(end_time - start_time))}"
expected_clock = f":: Time taken: \x1b[31m\
{time.strftime('%X', time.gmtime(end_time - start_time))}\x1b[0m"
expected_clock = f"{expected_clock}"
self.assertEqual(data_gen.clock, expected_clock)

def test_generate_with_conf(self):
Expand Down Expand Up @@ -292,7 +293,7 @@ def test_output_csv(self, mock_saveInCSV):
format="csv", choice="m")

# Call the output method and check if the saveInCSV method is called
data_gen.output()
data_gen.generateMockData()
mock_saveInCSV.assert_called_once()

@patch('sdgp.sdgp.DataGenerator.saveInParquet')
Expand All @@ -304,7 +305,7 @@ def test_output_parquet(self, mock_saveInParquet):

# Call the output method and check if the
# saveInParquet method is called
data_gen.output()
data_gen.generateMockData()
mock_saveInParquet.assert_called_once()

@patch('sdgp.sdgp.DataGenerator.generateWithConf')
Expand Down

0 comments on commit a87b533

Please sign in to comment.