コード例 #1
0
ファイル: test_scope.py プロジェクト: piller-imre/grimoire-tk
 def test_get_documents_with_multiple_tags(self):
     scope = Scope(database=self._database)
     tag_selections = {
         (1, 2): [1, 5],
         (1, 3): [2],
         (1, 4): [3],
         (1, 5): [5],
         (1, 6): [],
         (2, 5): [5],
         (3, 6): [7],
         (1, 2, 5): [5],
         (3, 5, 6): [],
         (1, 2, 3, 4, 5, 6): []
     }
     for selection, document_ids in tag_selections.items():
         self.assertEqual(scope.get_concept_tags(), [])
         for tag_id in selection:
             scope.add_tag(tag_id)
         documents = scope.get_concept_documents()
         self.assertEqual(len(documents), len(document_ids))
         for document in documents:
             self.assertIn(document.id, document_ids)
         for tag_id in selection:
             scope.remove_tag(tag_id)
         self.assertEqual(scope.get_concept_tags(), [])
コード例 #2
0
ファイル: test_scope.py プロジェクト: piller-imre/grimoire-tk
 def test_tag_creation_without_document(self):
     scope = Scope(database=self._database)
     self.assertEqual(scope.get_concept_tags(), [])
     tag = scope.create_tag('n+1')
     scope.add_tag(tag.id)
     self.assertEqual(scope.get_concept_tag_ids(), [tag.id])
     self.assertEqual(set(scope.get_selection_only_tag_ids()),
                      {1, 2, 3, 4, 5, 6})
     self.assertEqual(scope.get_concept_documents(), [])
コード例 #3
0
ファイル: test_scope.py プロジェクト: piller-imre/grimoire-tk
 def test_initial_scope(self):
     scope = Scope(database=self._database)
     concept_document_ids = scope.get_concept_document_ids()
     self.assertEqual(set(concept_document_ids), {1, 2, 3, 4, 5, 6, 7, 8})
     concept_documents = scope.get_concept_documents()
     for concept_document in concept_documents:
         self.assertIn(concept_document.id, sample_documents)
         self.assertEqual(concept_document.name,
                          sample_documents[concept_document.id]['name'])
         self.assertEqual(concept_document.type,
                          sample_documents[concept_document.id]['type'])
         self.assertEqual(concept_document.path,
                          sample_documents[concept_document.id]['path'])
     concept_tag_ids = scope.get_concept_tag_ids()
     self.assertEqual(concept_tag_ids, [])
     concept_tags = scope.get_concept_tags()
     self.assertEqual(concept_tags, [])
     selection_document_ids = scope.get_selection_document_ids()
     self.assertEqual(selection_document_ids, [])
     selection_documents = scope.get_selection_documents()
     self.assertEqual(selection_documents, [])
     selection_tag_ids = scope.get_selection_tag_ids()
     self.assertEqual(set(selection_tag_ids), {1, 2, 3, 4, 5, 6})
     selection_tags = scope.get_selection_tags()
     for selection_tag in selection_tags:
         self.assertIn(selection_tag.id, sample_tags)
         self.assertEqual(selection_tag.name, sample_tags[selection_tag.id])
     concept_only_document_ids = scope.get_concept_only_document_ids()
     self.assertEqual(set(concept_only_document_ids),
                      set(concept_document_ids))
     concept_only_documents = scope.get_concept_only_documents()
     for concept_only_document in concept_only_documents:
         self.assertIn(concept_only_document.id, sample_documents)
         self.assertEqual(
             concept_only_document.name,
             sample_documents[concept_only_document.id]['name'])
         self.assertEqual(
             concept_only_document.type,
             sample_documents[concept_only_document.id]['type'])
         self.assertEqual(
             concept_only_document.path,
             sample_documents[concept_only_document.id]['path'])
     selection_only_tag_ids = scope.get_selection_only_tag_ids()
     self.assertEqual(set(selection_only_tag_ids), {1, 2, 3, 4, 5, 6})
     selection_only_tags = scope.get_selection_only_tags()
     for selection_only_tag in selection_only_tags:
         self.assertIn(selection_only_tag.id, sample_tags)
         self.assertEqual(selection_only_tag.name,
                          sample_tags[selection_only_tag.id])
コード例 #4
0
ファイル: test_scope.py プロジェクト: piller-imre/grimoire-tk
 def test_document_destroying(self):
     scope = Scope(database=self._database)
     document_counts = {
         1: [4, 3, 2, 1, 1, 0, 0, 0, 0],
         2: [3, 2, 2, 2, 1, 0, 0, 0, 0],
         3: [3, 3, 2, 2, 2, 2, 2, 1, 0],
         4: [2, 2, 2, 1, 1, 1, 0, 0, 0],
         5: [3, 3, 3, 3, 3, 2, 1, 1, 0],
         6: [2, 2, 2, 2, 1, 1, 1, 0, 0]
     }
     for i in range(9):
         if i > 0:
             scope.destroy_document(i)
         for tag_id in range(1, 7):
             scope.add_tag(tag_id)
             self.assertEqual(len(scope.get_concept_documents()),
                              document_counts[tag_id][i])
             scope.remove_tag(tag_id)
コード例 #5
0
ファイル: test_scope.py プロジェクト: piller-imre/grimoire-tk
 def test_get_documents_with_single_tag(self):
     scope = Scope(database=self._database)
     document_ids = {
         1: [1, 2, 3, 5],
         2: [1, 4, 5],
         3: [2, 7, 8],
         4: [3, 6],
         5: [5, 6, 8],
         6: [4, 7]
     }
     for tag_id, document_ids in document_ids.items():
         self.assertEqual(scope.get_concept_tags(), [])
         scope.add_tag(tag_id)
         documents = scope.get_concept_documents()
         self.assertEqual(len(documents), len(document_ids))
         for document in documents:
             self.assertIn(document.id, document_ids)
         scope.remove_tag(tag_id)
         self.assertEqual(scope.get_concept_tags(), [])
コード例 #6
0
ファイル: test_scope.py プロジェクト: piller-imre/grimoire-tk
 def test_document_clone_with_multiple_tags(self):
     scope = Scope(database=self._database)
     scope.add_tag(2)
     scope.add_tag(3)
     scope.add_tag(6)
     self.assertEqual(scope.get_concept_document_ids(), [])
     self.assertEqual(set(scope.get_concept_tag_ids()), {2, 3, 6})
     self.assertEqual(scope.get_selection_document_ids(), [])
     self.assertEqual(set(scope.get_selection_tag_ids()),
                      {1, 2, 3, 4, 5, 6})
     self.assertEqual(scope.get_concept_only_document_ids(), [])
     self.assertEqual(set(scope.get_selection_only_tag_ids()), {1, 4, 5})
     cloned_document = scope.clone_document(6)
     self.assertNotEqual(cloned_document.id, 6)
     self.assertEqual(scope.get_concept_document_ids(),
                      [cloned_document.id])
     self.assertEqual(set(scope.get_concept_tag_ids()), {2, 3, 6})
     self.assertEqual(scope.get_selection_document_ids(), [])
     self.assertEqual(set(scope.get_selection_tag_ids()),
                      {1, 2, 3, 4, 5, 6})
     self.assertEqual(scope.get_concept_only_document_ids(),
                      [cloned_document.id])
     self.assertEqual(set(scope.get_selection_only_tag_ids()), {1, 4, 5})
     scope.select_document(cloned_document.id)
     self.assertEqual(scope.get_concept_document_ids(),
                      [cloned_document.id])
     self.assertEqual(set(scope.get_concept_tag_ids()), {2, 3, 6})
     self.assertEqual(scope.get_selection_document_ids(),
                      [cloned_document.id])
     self.assertEqual(set(scope.get_selection_tag_ids()), {2, 3, 6})
     self.assertEqual(scope.get_concept_only_document_ids(), [])
     self.assertEqual(scope.get_selection_only_tag_ids(), [])
     scope.remove_tag(3)
     self.assertEqual(set(scope.get_concept_document_ids()),
                      {4, cloned_document.id})
     self.assertEqual(set(scope.get_concept_tag_ids()), {2, 6})
     self.assertEqual(scope.get_selection_document_ids(),
                      [cloned_document.id])
     self.assertEqual(set(scope.get_selection_tag_ids()), {2, 3, 6})
     self.assertEqual(scope.get_concept_only_document_ids(), [4])
     self.assertEqual(scope.get_selection_only_tag_ids(), [3])
     scope.remove_tag(2)
     self.assertEqual(set(scope.get_concept_document_ids()),
                      {4, 7, cloned_document.id})
     self.assertEqual(set(scope.get_concept_tag_ids()), {6})
     self.assertEqual(scope.get_selection_document_ids(),
                      [cloned_document.id])
     self.assertEqual(set(scope.get_selection_tag_ids()), {2, 3, 6})
     self.assertEqual(set(scope.get_concept_only_document_ids()), {4, 7})
     self.assertEqual(set(scope.get_selection_only_tag_ids()), {2, 3})
     scope.remove_tag(6)
     self.assertEqual(set(scope.get_concept_document_ids()),
                      {1, 2, 3, 4, 5, 6, 7, 8, cloned_document.id})
     self.assertEqual(scope.get_concept_tag_ids(), [])
     self.assertEqual(scope.get_selection_document_ids(),
                      [cloned_document.id])
     self.assertEqual(set(scope.get_selection_tag_ids()), {2, 3, 6})
     self.assertEqual(set(scope.get_concept_only_document_ids()),
                      {1, 2, 3, 4, 5, 6, 7, 8})
     self.assertEqual(set(scope.get_selection_only_tag_ids()), {2, 3, 6})
     scope.deselect_document(cloned_document.id)
     self.assertEqual(set(scope.get_concept_document_ids()),
                      {1, 2, 3, 4, 5, 6, 7, 8, cloned_document.id})
     self.assertEqual(scope.get_concept_tag_ids(), [])
     self.assertEqual(scope.get_selection_document_ids(), [])
     self.assertEqual(set(scope.get_selection_tag_ids()),
                      {1, 2, 3, 4, 5, 6})
     self.assertEqual(set(scope.get_concept_only_document_ids()),
                      {1, 2, 3, 4, 5, 6, 7, 8, cloned_document.id})
     self.assertEqual(set(scope.get_selection_only_tag_ids()),
                      {1, 2, 3, 4, 5, 6})
     document_counts = {1: 4, 2: 3 + 1, 3: 3 + 1, 4: 2, 5: 3, 6: 2 + 1}
     for tag_id, document_count in document_counts.items():
         scope.add_tag(tag_id)
         self.assertEqual(len(scope.get_concept_documents()),
                          document_count)
         scope.remove_tag(tag_id)