def test_no_usage(self):
     '''Test getting usage histograms when there is no usage'''
     from metrics import get_usage_histograms
     # Expected histogram (for all)
     expected = {year: 0 for year in range(1996, current_year + 1)}
     # Get the reads histograms
     hist = get_usage_histograms(testset)
     # and check the results
     histograms = ['all reads', 'refereed reads',
                   'all reads normalized', 'refereed reads normalized']
     for histogram in histograms:
         self.assertEqual(hist[histogram], expected)
     # and do the same for downloads
     hist = get_usage_histograms(testset, usage_type='downloads')
     histograms = ['all downloads',
                   'refereed downloads',
                   'all downloads normalized',
                   'refereed downloads normalized']
     for histogram in histograms:
         self.assertEqual(hist[histogram], expected)
Exemple #2
0
 def test_usage_histograms(self):
     '''Test getting the usage histograms'''
     from metrics import get_usage_histograms
     # First get the 'reads' histograms
     hist = get_usage_histograms(testset)
     # Every entry in the histogram for all papers should, by design,
     # equal the number of papers in the test set, from 1996 up to the
     # current year
     current_year = datetime.now().year
     expected = dict([(year,
                       expected_results['basic stats']['number of papers'])
                      for year in range(1996, current_year + 1)])
     self.assertEqual(hist['all reads'], expected)
     # and for the same reason, every entry in the histogram for refereed
     # papers should equal the number of refereed papers
     expected = dict([
         (year,
          expected_results['basic stats refereed']['number of papers'])
         for year in range(1996, current_year + 1)
     ])
     self.assertEqual(hist['refereed reads'], expected)
     # For the normalized histograms, each entry should equal the normalized
     # paper count. Because we're dealing with a dictionary of floats, we do
     # things slightly differently:
     # Check that all entries are equal
     self.assertEqual(len(set(hist['all reads normalized'].values())), 1)
     # and then check that one entry has the expected value
     self.assertAlmostEqual(
         hist['all reads normalized'].values()[0],
         expected_results['basic stats']['normalized paper count'])
     # Because the downloads have been constructed in the same way,
     # we only need to verify that the downloads histograms are the
     # same as the reads ones
     dhist = get_usage_histograms(testset, usage_type='downloads')
     self.assertEqual(hist['all reads'], dhist['all downloads'])
     self.assertEqual(hist['refereed reads'], dhist['refereed downloads'])
     self.assertEqual(hist['all reads normalized'],
                      dhist['all downloads normalized'])
     self.assertEqual(hist['refereed reads normalized'],
                      dhist['refereed downloads normalized'])
 def test_usage_histograms(self):
     '''Test getting the usage histograms'''
     from metrics import get_usage_histograms
     # First get the 'reads' histograms
     hist = get_usage_histograms(testset)
     # Every entry in the histogram for all papers should, by design,
     # equal the number of papers in the test set, from 1996 up to the
     # current year
     current_year = datetime.now().year
     expected = dict([(year, expected_results['basic stats'][
                     'number of papers']) for year in
                     range(1996, current_year + 1)])
     self.assertEqual(hist['all reads'], expected)
     # and for the same reason, every entry in the histogram for refereed
     # papers should equal the number of refereed papers
     expected = dict([(year, expected_results['basic stats refereed'][
                     'number of papers']) for year in
                     range(1996, current_year + 1)])
     self.assertEqual(hist['refereed reads'], expected)
     # For the normalized histograms, each entry should equal the normalized
     # paper count. Because we're dealing with a dictionary of floats, we do
     # things slightly differently:
     # Check that all entries are equal
     self.assertEqual(len(set(hist['all reads normalized'].values())), 1)
     # and then check that one entry has the expected value
     self.assertAlmostEqual(hist['all reads normalized'].values()[0],
                            expected_results['basic stats'][
                            'normalized paper count'])
     # Because the downloads have been constructed in the same way,
     # we only need to verify that the downloads histograms are the
     # same as the reads ones
     dhist = get_usage_histograms(testset, usage_type='downloads')
     self.assertEqual(hist['all reads'], dhist['all downloads'])
     self.assertEqual(hist['refereed reads'], dhist['refereed downloads'])
     self.assertEqual(
         hist['all reads normalized'],
         dhist['all downloads normalized'])
     self.assertEqual(
         hist['refereed reads normalized'],
         dhist['refereed downloads normalized'])
 def test_no_usage(self):
     '''Test getting usage histograms when there is no usage'''
     from metrics import get_usage_histograms
     # Expected histogram (for all)
     expected = {year: 0 for year in range(1996, current_year + 1)}
     # Get the reads histograms
     hist = get_usage_histograms(testset)
     # and check the results
     histograms = [
         'all reads', 'refereed reads', 'all reads normalized',
         'refereed reads normalized'
     ]
     for histogram in histograms:
         self.assertEqual(hist[histogram], expected)
     # and do the same for downloads
     hist = get_usage_histograms(testset, usage_type='downloads')
     histograms = [
         'all downloads', 'refereed downloads', 'all downloads normalized',
         'refereed downloads normalized'
     ]
     for histogram in histograms:
         self.assertEqual(hist[histogram], expected)