-
-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ADD no code instructions and FIX Tests (#45)
* Add no code instructions * FIX: End year in Debug (Test) mode * Reduce python version tests and reverse end year * FIX: Simplify and fix tests * HOTFIX: test_cli_cit_per_year_sorted * HOTFIX: citation values * UPDATE: Test once per month * REMOVE: Dependencies in GA tests * ADD: requirements.txt to setup.py * Add sponsor HOTFIX: Include explicit dependencies HOTFIX: Linebreak HOTFIX: Comma
- Loading branch information
Showing
5 changed files
with
57 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
buymeacoffee: fernandowip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,91 +1,55 @@ | ||
import unittest | ||
from unittest.mock import patch | ||
import sortgs | ||
import os | ||
import pandas as pd | ||
|
||
class TestSortGS(unittest.TestCase): | ||
@classmethod | ||
def setUpClass(self): | ||
'''run once before all tests''' | ||
os.system("python sortgs.py --debug --kw 'machine learning' --nresults 10 --endyear 2022") | ||
self.df_top_10=pd.read_csv('machine_learning.csv') | ||
|
||
os.system("python sortgs.py --debug --kw 'machine learning' --nresults 20 --endyear 2022") | ||
self.df_top_20=pd.read_csv('machine_learning.csv') | ||
def setUpClass(cls): | ||
'''Run once before all tests''' | ||
os.system("sortgs 'machine learning' --debug --nresults 10 --endyear 2022") | ||
cls.df_top_10_cli = pd.read_csv('machine_learning.csv') | ||
|
||
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') | ||
os.system("sortgs 'machine learning' --debug --nresults 10 --endyear 2022 --sortby 'cit/year'") | ||
cls.df_top_sorted_cit_per_year_cli = 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') | ||
def test_get_10_results_cli(self): | ||
self.assertEqual(len(self.df_top_10_cli), 10) | ||
|
||
os.system("sortgs 'machine learning' --debug --nresults 20 --endyear 2022") | ||
self.df_top_20_cli=pd.read_csv('machine_learning.csv') | ||
def test_is_sorted_by_citations(self): | ||
df = self.df_top_10_cli | ||
top_citations = list(df.Citations.values[:5]) | ||
self.assertEqual(top_citations, [3166, 2853, 2416, 948, 830]) | ||
|
||
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) | ||
|
||
def test_get_20_results(self): | ||
self.assertEqual(len(self.df_top_20), 20) | ||
|
||
def test_is_sorted(self): | ||
df=self.df_top_20 | ||
top_citations=list(df.Citations.values[:5]) | ||
self.assertEqual(top_citations, [49230, 8603, 3166, 3069, 2853]) | ||
|
||
def test_top_result(self): | ||
df=self.df_top_20 | ||
top_author = str(df.Author.values[0]) | ||
def test_top_result_cli(self): | ||
df = self.df_top_10_cli | ||
top_author = str(df.Author.values[0]).strip() | ||
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]) | ||
self.assertEqual(top_results, ['Shale', 3166, 352]) | ||
|
||
def test_cit_per_year_sorted(self): | ||
df=self.df_top_sorted_cit_per_year | ||
top_citations=list(df.Citations.values[:5]) | ||
df = self.df_top_sorted_cit_per_year_cli | ||
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]]) | ||
self.assertEqual(top_cit_per_year, [571, 352, 302, 85, 79]) | ||
|
||
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]) | ||
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]]) | ||
|
||
# Convert np.int64 values to Python int | ||
top_citations = [int(c) for c in top_citations] | ||
top_cit_per_year = [int(c) for c in top_cit_per_year] | ||
|
||
top_results = [top_citations, top_cit_per_year] | ||
self.assertEqual(top_results, [ | ||
[2853, 3166, 2416, 598, 948], | ||
[571, 352, 302, 85, 79] | ||
]) | ||
|
||
if __name__=='__main__': | ||
unittest.main() |