Skip to content

Commit

Permalink
Tests does not rely on pickle anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
romainx committed Jan 16, 2015
1 parent 6035b9f commit 5e13c69
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 114 deletions.
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@

**Panorama** is a [Pelican][LK_PELIC] plugin to generate **statistics from blog posts** (number of posts per year, categories and so on) and display them as **beautiful charts**.

No more talking, see:

- the [example page](http://cdn.rawgit.com/romainx/panorama/master/tests/test_output/all_charts.html),
- a [live example](http://aubonroman.com/stats.html),
- or a screenshot below
No more talking, see a [live example](http://aubonroman.com/stats.html), or the screenshot below.

![Panorama screenshot](panorama_screenshot.png "Panorama screenshot")

Expand Down
30 changes: 0 additions & 30 deletions TODO.md

This file was deleted.

1 change: 0 additions & 1 deletion panorama/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@
"""

__version__ = '0.1'
__author__ = 'romainx'

from .panorama import *
16 changes: 1 addition & 15 deletions panorama/data_factory.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from pandas import DataFrame, Series, read_pickle
from pandas import DataFrame, Series


FUNCTIONS_ALLOWED = ['count_article_by_column_by_year', 'top_article', 'count_article', 'count_article_by_year',
Expand All @@ -21,20 +21,6 @@ def __init__(self, metadata_columns, tag_columns):
self.metadata_columns = metadata_columns
self.tag_columns = tag_columns

def load_data(self, path):
""" Used, for test purpose, to load data from a pickle file.
:param path: the path of the file.
"""
self.data = read_pickle(path)

def save_data(self, path):
""" Used, for test purpose, to save data to a pickle file.
:param path: the path of the file.
"""
self.data.to_pickle(path)

def parse_data(self, articles):
""" Responsible to parse articles in order to extract data.
Data is extracted as a DataFrame containing the following columns:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_data/content/article_with_metadata.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
This is a super article !
#########################

:tags: foo, bar, foobar
:tags: Roman Noir, bar, foobar
:date: 2010-12-02 10:14
:modified: 2010-12-02 10:20
:category: yeah
Expand Down
Binary file removed tests/test_data/p/article_data.p
Binary file not shown.
95 changes: 49 additions & 46 deletions tests/test_output/all_charts.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,55 @@
<script src="https://raw.githubusercontent.com/novus/nvd3/master/nv.d3.min.js"></script>
</head>
<body>
<h1>nb_article_by_year</h1>

<div id="nb_article_by_year">
<svg style="width:700px;height:300px;"></svg>
</div>


<script>



data_nb_article_by_year=[{"values": [{"y": 1, "x": 2007}, {"y": 2, "x": 2008}, {"y": 1, "x": 2010}, {"y": 7, "x": 2014}], "key": "title", "yAxis": "1"}];


nv.addGraph(function() {
var chart = nv.models.discreteBarChart();

chart.margin({top: 30, right: 60, bottom: 20, left: 60});

var datum = data_nb_article_by_year;



chart.yAxis
.tickFormat(d3.format(',.0f'));








d3.select('#nb_article_by_year svg')
.datum(datum)
.transition().duration(500)
.attr('width', 700)
.attr('height', 300)
.call(chart);


});





</script>

<h1>nb_article_by_category</h1>
<div id="nb_article_by_category"><svg style="width:700px;height:300px;"></svg></div>

Expand Down Expand Up @@ -127,52 +176,6 @@ <h1>nb_article_by_category_year</h1>




</script>

<h1>nb_article_by_year</h1>
<div id="nb_article_by_year"><svg style="width:700px;height:300px;"></svg></div>



<script>



data_nb_article_by_year=[{"values": [{"y": 1, "x": 2007}, {"y": 2, "x": 2008}, {"y": 1, "x": 2010}, {"y": 7, "x": 2014}], "key": "title", "yAxis": "1"}];


nv.addGraph(function() {
var chart = nv.models.discreteBarChart();

chart.margin({top: 30, right: 60, bottom: 20, left: 60});

var datum = data_nb_article_by_year;



chart.yAxis
.tickFormat(d3.format(',.0f'));








d3.select('#nb_article_by_year svg')
.datum(datum)
.transition().duration(500)
.attr('width', 700)
.attr('height', 300)
.call(chart);


});



</script>

</body>
Expand Down
30 changes: 14 additions & 16 deletions tests/test_panorama.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from functools import partial
import os
import io
import sys
import logging

from pandas.util.testing import assert_series_equal
Expand Down Expand Up @@ -34,13 +33,15 @@
CONF_ERR_FILE = os.path.join(CONF_DIR, 'panorama_error.yml')


def create_generator():
settings = get_settings(filenames={})
settings['CACHE_CONTENT'] = False # cache not needed for this logic tests
return ArticlesGenerator(context=settings.copy(), settings=settings,
path=CONTENT_DIR, theme=settings['THEME'], output_path=None)

class TestGenerator(unittest.TestCase):
def setUp(self):
self.settings = get_settings(filenames={})
self.settings['CACHE_CONTENT'] = False # cache not needed for this logic tests
self.generator = ArticlesGenerator(
context=self.settings.copy(), settings=self.settings,
path=CONTENT_DIR, theme=self.settings['THEME'], output_path=None)
self.generator = create_generator()

def test_generate_default(self):
# Registering plugin
Expand All @@ -62,17 +63,14 @@ def tearDown(self):
output_file.write(self.template_test_page.render(panorama_charts=self.generator.context['panorama_charts']))


# TODO fix pickle to be usable in Python 2 & 3
@unittest.skipIf(sys.version_info > (3, 0),
'Not supported in Python 3.x due to test data decoding (pickle)')
class TestData(unittest.TestCase):
def setUp(self):
# Initializing the conf factory
self.conf_factory = ConfFactory()
self.conf_factory.configure(CONF_FILE)
# Initializing the data factory
self.data_factory = self.conf_factory.data_factory
self.data_factory.load_data(TEST_DATA_FILE)
generator = create_generator()
generator.generate_context()
conf_factory = ConfFactory()
conf_factory.configure(CONF_FILE)
self.data_factory = conf_factory.data_factory
self.data_factory.parse_data(generator.articles)

def test_count_article_by_column_by_year(self):
self.assertEqual(len(count_article_by_column_by_year(self.data_factory.data, 'genre')), 5)
Expand All @@ -82,7 +80,7 @@ def test_count_article_by_column(self):
assert_series_equal(count_article_by_column(self.data_factory.data, 'genre'), expected_result)

def test_count_article_by_year(self):
expected_result = Series({2007: 1, 2008: 2, 2014: 7})
expected_result = Series({2007: 1, 2008: 2, 2010: 1, 2014: 7})
assert_series_equal(count_article_by_year(self.data_factory.data), expected_result)

def test_top_article(self):
Expand Down

0 comments on commit 5e13c69

Please sign in to comment.