Skip to content

Commit

Permalink
Add CLI commands to test
Browse files Browse the repository at this point in the history
  • Loading branch information
WittmannF committed Nov 16, 2023
1 parent 3031dc3 commit 65edc1b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ jobs:
- name: Test with unittest
run: python -m unittest
- name: Test CLI Command
run: sortgs 'machine learning' --nresults 10 # Replace with an appropriate CLI test command
run: sortgs 'machine learning' --nresults 10
38 changes: 38 additions & 0 deletions test/test_sortgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ def setUpClass(self):

os.system("python sortgs.py --debug --kw 'machine learning' --nresults 20 --endyear 2022 --sortby 'cit/year'")
self.df_top_sorted_cit_per_year=pd.read_csv('machine_learning.csv')

# Repeat the above, but testing the cli command
os.system("sortgs 'machine learning' --debug --nresults 10 --endyear 2022")
self.df_top_10_cli=pd.read_csv('machine_learning.csv')

os.system("sortgs 'machine learning' --debug --nresults 20 --endyear 2022")
self.df_top_20_cli=pd.read_csv('machine_learning.csv')

os.system("sortgs 'machine learning' --debug --nresults 20 --endyear 2022 --sortby 'cit/year'")
self.df_top_sorted_cit_per_year_cli=pd.read_csv('machine_learning.csv')

def test_get_10_results(self):
self.assertEqual(len(self.df_top_10), 10)
Expand Down Expand Up @@ -47,6 +57,34 @@ def test_cit_per_year_sorted(self):
def test_csv_exists(self):
os.system("python sortgs.py --debug --kw 'machine learning' --nresults 10")
self.assertTrue(os.path.exists('machine_learning.csv'))

def test_cli_get_10_results(self):
self.assertEqual(len(self.df_top_10_cli), 10)

def test_cli_get_20_results(self):
self.assertEqual(len(self.df_top_20_cli), 20)

def test_cli_is_sorted(self):
df=self.df_top_20_cli
top_citations=list(df.Citations.values[:5])
self.assertEqual(top_citations, [49230, 8603, 3166, 3069, 2853])

def test_cli_top_result(self):
df=self.df_top_20_cli
top_author = str(df.Author.values[0])
top_citation = int(df.Citations.values[0])
top_cit_per_year = int(df['cit/year'].values[0])
top_results = [top_author, top_citation, top_cit_per_year]
self.assertEqual(top_results, [' Bishop', 49230, 2896])

def test_cli_cit_per_year_sorted(self):
df=self.df_top_sorted_cit_per_year_cli
top_citations=list(df.Citations.values[:5])
top_cit_per_year = list(df['cit/year'].values[:5])
top_results = [top_citations, top_cit_per_year]
self.assertEqual(top_results, [[49230, 8603, 2853, 3166, 2416],
[2896, 782, 571, 352, 302]])



if __name__=='__main__':
Expand Down

0 comments on commit 65edc1b

Please sign in to comment.