test_data.py 2.76 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
#!/usr/bin/env python
"""
    dataTests - Data classes test case
"""
__author__ = "Tassia Camoes Araujo <tassia@gmail.com>"
__copyright__ = "Copyright (C) 2011 Tassia Camoes Araujo"
__license__ = """
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""

import unittest
import xapian

from apprecommender.data import PopconSubmission, axi_search_pkg_tags
from apprecommender.config import Config


class AxiSearchTests(unittest.TestCase):
    @classmethod
    def setUpClass(self):
        cfg = Config()
        self.axi = xapian.Database(cfg.axi)

    def test_search_pkg_tags(self):
36 37
        tags = axi_search_pkg_tags(self.axi, 'vim')
        self.assertEqual(set(tags), set(['XTscope::application',
38
                                         'XTrole::program',
39 40 41 42 43 44 45 46
                                         'XTimplemented-in::c',
                                         'XTworks-with::unicode',
                                         'XTworks-with::text',
                                         'XTuse::editing',
                                         'XTinterface::commandline',
                                         'XTdevel::editor',
                                         'XTuitoolkit::ncurses',
                                         'XTinterface::text-mode']))
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70


class PopconSubmissionTests(unittest.TestCase):
    @classmethod
    def setUpClass(self):
        self.submission_path = "apprecommender/tests/test_data/test_popcon"
        self.submission = PopconSubmission(self.submission_path)

    def test_user_id(self):
        with open(self.submission_path) as popcon_file:
            user_id = popcon_file.readline().split()[2].lstrip("ID:")
        self.assertEqual(self.submission.user_id, user_id)

    def test_load(self):
        with open(self.submission_path) as popcon_file:
            size = len(popcon_file.readlines())
        self.assertEqual(len(self.submission.packages), size - 2)

    def test_str(self):
        output = "\nPopularity-contest submission ID "
        output += "8b44fcdbcf676e711a153d5db099test\n "
        output += "dash: 1\n perl-base: 1\n libusbmuxd1: 1\n "
        output += "libc6-i686: 1\n libc6: 1"
        self.assertEqual(self.submission.__str__(), output)