Commit a69758a843276f06f9998c5c554d949315c629d4

Authored by Tássia Camões Araújo
1 parent 7f0ce65a
Exists in master and in 1 other branch add_vagrant

Unit tests implementation.

src/tests/.pxi/flintlock 0 → 100644
src/tests/.pxi/iamchert 0 → 100644
No preview for this file type
src/tests/.pxi/postlist.DB 0 → 100644
src/tests/.pxi/postlist.baseA 0 → 100644
No preview for this file type
src/tests/.pxi/record.DB 0 → 100644
src/tests/.pxi/record.baseA 0 → 100644
No preview for this file type
src/tests/.pxi/termlist.DB 0 → 100644
src/tests/.pxi/termlist.baseA 0 → 100644
No preview for this file type
src/tests/.user_tests.py.swp 0 → 100644
No preview for this file type
src/tests/package-xapian-index 0 → 100644
... ... @@ -0,0 +1,10 @@
  1 +aaphoto: implemented-in::c, interface::commandline, role::program, use::editing, works-with::image
  2 +dia: implemented-in::c, interface::x11, role::program, scope::application, suite::gnu, uitoolkit::gtk, use::editing, works-with::image, works-with::image:vector, x11::application
  3 +eog: implemented-in::c, interface::x11, role::program, scope::application, suite::gnome, uitoolkit::gtk, use::viewing, works-with-format::jpg, works-with-format::png, works-with::image, works-with::image:raster, works-with::image:vector, x11::application
  4 +emacs: devel::editor, role::dummy, role::metapackage, special::meta, suite::emacs, suite::gnu, use::editing
  5 +ferret: devel::modelling, role::program, scope::application, suite::gnu, works-with::db
  6 +festival: accessibility::speech, devel::interpreter, implemented-in::scheme, interface::text-mode, network::client, network::server, role::program, sound::speech, uitoolkit::ncurses, works-with::audio
  7 +file: admin::forensics, implemented-in::c, interface::commandline, role::program, scope::utility, use::analysing, use::scanning, works-with::file
  8 +gimp: implemented-in::c, interface::x11, role::program, scope::application, suite::gimp, suite::gnu, uitoolkit::gtk, use::editing, works-with-format::gif, works-with-format::jpg, works-with-format::pdf, works-with-format::png, works-with-format::tiff, works-with::image, works-with::image:raster, works-with::text, x11::application
  9 +inkscape: implemented-in::c, implemented-in::c++, interface::x11, role::program, scope::application, uitoolkit::gtk, use::editing, works-with-format::pdf, works-with-format::postscript, works-with-format::svg, works-with-format::tex, works-with::image, works-with::image:vector, x11::application
  10 +xpdf: implemented-in::c++, interface::x11, role::program, scope::application, uitoolkit::motif, use::viewing, works-with-format::pdf, works-with::text, x11::application
... ...
src/tests/pxi.py 0 → 100644
... ... @@ -0,0 +1,37 @@
  1 +#!/usr/bin/env python
  2 +"""
  3 + userTests - User class test case
  4 +"""
  5 +__author__ = "Tassia Camoes Araujo <tassia@gmail.com>"
  6 +__copyright__ = "Copyright (C) 2011 Tassia Camoes Araujo"
  7 +__license__ = """
  8 + This program is free software: you can redistribute it and/or modify
  9 + it under the terms of the GNU General Public License as published by
  10 + the Free Software Foundation, either version 3 of the License, or
  11 + (at your option) any later version.
  12 +
  13 + This program is distributed in the hope that it will be useful,
  14 + but WITHOUT ANY WARRANTY; without even the implied warranty of
  15 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16 + GNU General Public License for more details.
  17 +
  18 + You should have received a copy of the GNU General Public License
  19 + along with this program. If not, see <http://www.gnu.org/licenses/>.
  20 +"""
  21 +
  22 +import xapian
  23 +import sys
  24 +sys.path.insert(0,'../')
  25 +
  26 +class PkgXapianIndex(xapian.WritableDatabase):
  27 + def __init__(self):
  28 + xapian.WritableDatabase.__init__(self,".pxi",xapian.DB_CREATE_OR_OVERWRITE)
  29 + pxi_file = open("package-xapian-index")
  30 + for line in pxi_file:
  31 + doc = xapian.Document()
  32 + package_name = line.split()[0].rstrip(":")
  33 + doc.add_term("XP"+package_name)
  34 + package_tags = [tag.rstrip(",") for tag in line.split()[1:]]
  35 + for tag in package_tags:
  36 + doc.add_term("XT"+tag)
  37 + self.add_document(doc)
... ...
src/tests/pxi.pyc 0 → 100644
No preview for this file type
src/tests/runner.py 0 → 100755
... ... @@ -0,0 +1,26 @@
  1 +#!/usr/bin/env python
  2 +"""
  3 + tests - execution of the whole set of tests suites.
  4 +"""
  5 +__author__ = "Tassia Camoes Araujo <tassia@gmail.com>"
  6 +__copyright__ = "Copyright (C) 2011 Tassia Camoes Araujo"
  7 +__license__ = """
  8 + This program is free software: you can redistribute it and/or modify
  9 + it under the terms of the GNU General Public License as published by
  10 + the Free Software Foundation, either version 3 of the License, or
  11 + (at your option) any later version.
  12 +
  13 + This program is distributed in the hope that it will be useful,
  14 + but WITHOUT ANY WARRANTY; without even the implied warranty of
  15 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16 + GNU General Public License for more details.
  17 +
  18 + You should have received a copy of the GNU General Public License
  19 + along with this program. If not, see <http://www.gnu.org/licenses/>.
  20 +"""
  21 +
  22 +import unittest2
  23 +import user_tests
  24 +
  25 +runner = unittest2.TextTestRunner()
  26 +runner.run(user_tests.suite())
... ...
src/tests/user_tests.py 0 → 100755
... ... @@ -0,0 +1,138 @@
  1 +#!/usr/bin/env python
  2 +"""
  3 + userTests - User class test case
  4 +"""
  5 +__author__ = "Tassia Camoes Araujo <tassia@gmail.com>"
  6 +__copyright__ = "Copyright (C) 2011 Tassia Camoes Araujo"
  7 +__license__ = """
  8 + This program is free software: you can redistribute it and/or modify
  9 + it under the terms of the GNU General Public License as published by
  10 + the Free Software Foundation, either version 3 of the License, or
  11 + (at your option) any later version.
  12 +
  13 + This program is distributed in the hope that it will be useful,
  14 + but WITHOUT ANY WARRANTY; without even the implied warranty of
  15 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16 + GNU General Public License for more details.
  17 +
  18 + You should have received a copy of the GNU General Public License
  19 + along with this program. If not, see <http://www.gnu.org/licenses/>.
  20 +"""
  21 +
  22 +import operator
  23 +import math
  24 +import unittest2
  25 +import xapian
  26 +import sys
  27 +sys.path.insert(0,'../')
  28 +from user import *
  29 +from config import *
  30 +from data import *
  31 +from pxi import *
  32 +
  33 +def suite():
  34 + return unittest2.TestLoader().loadTestsFromTestCase(UserTests)
  35 +
  36 +class UserTests(unittest2.TestCase):
  37 + @classmethod
  38 + def setUpClass(self):
  39 + cfg = Config()
  40 + self.axi = xapian.Database(cfg.axi)
  41 + self.user = User({"gimp":1,"aaphoto":1,"eog":1,"emacs":1})
  42 + self.pxi = PkgXapianIndex()
  43 +
  44 + def test_hash(self):
  45 + new_user = User(dict())
  46 + self.assertIsNotNone(new_user.id)
  47 + self.assertNotEqual(self.user.id, new_user.id)
  48 +
  49 + def test_profile_default(self):
  50 + new_user = User(dict())
  51 + desktop = set(["x11", "accessibility", "game", "junior", "office",
  52 + "interface::x11"])
  53 + self.assertEqual(new_user.demographic_profile,desktop)
  54 +
  55 + def test_profile_desktop(self):
  56 + self.user.set_demographic_profile(set(["desktop"]))
  57 + desktop = set(["x11", "accessibility", "game", "junior", "office",
  58 + "interface::x11"])
  59 + self.assertEqual(self.user.demographic_profile,desktop)
  60 +
  61 + def test_profile_admin(self):
  62 + self.user.set_demographic_profile(set(["admin"]))
  63 + admin = set(["admin", "hardware", "mail", "protocol",
  64 + "network", "security", "web", "interface::web"])
  65 + self.assertEqual(self.user.demographic_profile,admin)
  66 +
  67 + def test_profile_devel(self):
  68 + self.user.set_demographic_profile(set(["devel"]))
  69 + devel = set(["devel", "role::devel-lib", "role::shared-lib"])
  70 + self.assertEqual(self.user.demographic_profile,devel)
  71 +
  72 + def test_profile_art(self):
  73 + self.user.set_demographic_profile(set(["art"]))
  74 + art = set(["field::arts", "sound"])
  75 + self.assertEqual(self.user.demographic_profile,art)
  76 +
  77 + def test_profile_science(self):
  78 + self.user.set_demographic_profile(set(["science"]))
  79 + science = set(["science", "biology", "field::astronomy",
  80 + "field::aviation", "field::biology",
  81 + "field::chemistry", "field::eletronics",
  82 + "field::finance", "field::geography",
  83 + "field::geology", "field::linguistics",
  84 + "field::mathematics", "field::medicine",
  85 + "field::meteorology", "field::physics",
  86 + "field::statistics"])
  87 + self.assertEqual(self.user.demographic_profile,science)
  88 +
  89 + def test_multi_profile(self):
  90 + self.user.set_demographic_profile(set(["devel","art"]))
  91 + devel_art = set(["devel", "role::devel-lib", "role::shared-lib",
  92 + "field::arts", "sound"])
  93 + self.assertEqual(self.user.demographic_profile,devel_art)
  94 +
  95 + self.user.set_demographic_profile(set(["art","admin","desktop"]))
  96 + desktop_art_admin = set(["x11", "accessibility", "game", "junior",
  97 + "office", "interface::x11", "field::arts",
  98 + "sound", "admin", "hardware", "mail",
  99 + "protocol", "network", "security", "web",
  100 + "interface::web"])
  101 + self.assertEqual(self.user.demographic_profile,desktop_art_admin)
  102 +
  103 + def test_items(self):
  104 + self.assertEqual(self.user.items(),set(["gimp","aaphoto","eog","emacs"]))
  105 +
  106 + def test_axi_tag_profile(self):
  107 + enquire = xapian.Enquire(self.pxi)
  108 + relevant_dict = {}
  109 + non_relevant_dict = {}
  110 + package_terms = ["XP"+package for package in self.user.items()]
  111 + enquire.set_query(xapian.Query(xapian.Query.OP_OR,package_terms))
  112 + mset = enquire.get_mset(0, self.pxi.get_doccount(), None, None)
  113 + tag_terms = set()
  114 + for m in mset:
  115 + tag_terms = [x.term for x in m.document.termlist()
  116 + if x.term.startswith("XT")]
  117 + for tag in tag_terms:
  118 + if tag in relevant_dict:
  119 + relevant_dict[tag] = relevant_dict[tag]+1
  120 + else:
  121 + relevant_dict[tag] = 1
  122 + rank = {}
  123 + for tag,count in relevant_dict.items():
  124 + non_relevant_dict[tag] = self.pxi.get_termfreq(tag)-count
  125 + if non_relevant_dict[tag]>0:
  126 + rank[tag] = relevant_dict[tag]/float(non_relevant_dict[tag])
  127 + #print "relevant",relevant_dict
  128 + #print "non_relevant",non_relevant_dict
  129 + #print sorted(rank.items(), key=operator.itemgetter(1))
  130 + #[FIXME] get ths value based on real ranking
  131 + self.assertEqual(set(self.user.axi_tag_profile(self.pxi,4)),
  132 + set(["XTuse::editing", "XTworks-with::image",
  133 + "XTworks-with-format::png",
  134 + "XTworks-with-format::jpg"]))
  135 +
  136 +
  137 +if __name__ == '__main__':
  138 + unittest2.main()
... ...
src/tests/user_tests.pyc 0 → 100644
No preview for this file type