Exemple #1
0
 def test_freeze(self):
     l = DataList(self.data_items)
     #
     l.freeze()
     self.assertTrue(l.frozen)
     with self.assertRaises(TypeError):
         l[0] = self.data_items[0]
Exemple #2
0
 def test_slice(self):
     i1 = self.data_items[0]
     expect = self.data_items.copy()
     expect[5:6] = [i1]
     l = DataList(self.data_items)
     # Slice read
     self.assertListEqual(l[:], self.data_items[:])
     self.assertListEqual(l[:1],self.data_items[:1])
     self.assertListEqual(l[1:], self.data_items[1:])
     self.assertListEqual(l[2:2], self.data_items[2:2])
     self.assertListEqual(l[2:3], self.data_items[2:3])
     self.assertListEqual(l[2:4], self.data_items[2:4])
     self.assertListEqual(l[-1:], self.data_items[-1:])
     self.assertListEqual(l[:-1], self.data_items[:-1])
     # Slice set
     l[5:6] = [i1]
     self.assertListEqual(l, expect)
     # With type_spec
     l = DataList(self.data_items, Item)
     with self.assertRaises(TypeError):
         l[5:6] = [self.data_desc[0]]
     l[5:6] = [i1]
     self.assertListEqual(l, expect)
     # Slice remove
     l = DataList(self.data_items)
     del l[:]
     self.assertListEqual(l, [])
     # Frozen
     l = DataList(self.data_items)
     with self.assertRaises(TypeError):
         l.freeze()
         del l[:]
Exemple #3
0
 def test_filterfalse(self):
     l = DataList(self.data_items)
     #
     result = l.filterfalse(lambda x: x.key > 5)
     self.assertIsInstance(result, GeneratorType)
     self.assertListEqual(list(result), self.data_items[:5])
     #
     result = l.filterfalse('item.key > 5')
     self.assertListEqual(list(result), self.data_items[:5])
Exemple #4
0
 def test_list_delete(self):
     i1, i2, i3 = self.data_items[:3]
     l = DataList(self.data_items[:3])
     #
     del l[1]
     self.assertListEqual(l, [i1, i3])
     # Frozen
     with self.assertRaises(TypeError):
         l.freeze()
         del l[1]
Exemple #5
0
 def test_occurrence(self):
     l = DataList(self.data_items)
     expect = sum(1 for x in l if x.key > 5)
     #
     result = l.occurrence(lambda x: x.key > 5)
     self.assertIsInstance(result, int)
     self.assertEqual(result, expect)
     #
     result = l.occurrence('item.key > 5')
     self.assertEqual(result, expect)
Exemple #6
0
 def test_report(self):
     l = DataList(self.data_desc[:2])
     expect = [(1, 'Item 01', "This is item 'Item 01'"),
               (2, 'Item 02', "This is item 'Item 02'")]
     #
     rpt = l.report(lambda x: (x.key, x.item.name, x.description))
     self.assertIsInstance(rpt, GeneratorType)
     self.assertListEqual(list(rpt), expect)
     #
     rpt = list(l.report('item.key', 'item.item.name', 'item.description'))
     self.assertListEqual(rpt, expect)
Exemple #7
0
 def test_list_acess(self):
     l = DataList(self.data_items)
     # Simple
     self.assertEqual(l[2], self.data_items[2])
     with self.assertRaises(IndexError):
         l[20]
     # With type_spec
     l = DataList(self.data_items, type_spec=Item)
     self.assertEqual(l[2], self.data_items[2])
     # With key expr
     l = DataList(self.data_items, key_expr=self.key_item)
     self.assertEqual(l[2], self.data_items[2])
Exemple #8
0
 def test_remove(self):
     i1, i2, i3 = self.data_items[:3]
     l = DataList(self.data_items[:3])
     #
     l.remove(i2)
     self.assertListEqual(l, [i1, i3])
     # Frozen
     with self.assertRaises(TypeError):
         l.freeze()
         l.remove(i1)
Exemple #9
0
 def test_split(self):
     exp_left = [x for x in self.data_items if x.key > 5]
     exp_right = [x for x in self.data_items if not x.key > 5]
     l = DataList(self.data_items)
     #
     res_left, res_right = l.split(lambda x: x.key > 5)
     self.assertIsInstance(res_left, DataList)
     self.assertIsInstance(res_right, DataList)
     self.assertListEqual(res_left, exp_left)
     self.assertListEqual(res_right, exp_right)
     self.assertEqual(len(res_left) + len(res_right), len(l))
     #
     res_left, res_right = l.split('item.key > 5')
     self.assertIsInstance(res_left, DataList)
     self.assertIsInstance(res_right, DataList)
     self.assertListEqual(res_left, exp_left)
     self.assertListEqual(res_right, exp_right)
     self.assertEqual(len(res_left) + len(res_right), len(l))
Exemple #10
0
 def __clear(self):
     self.gstat_version = None
     self.system_change_number = None
     self.executed = None
     self.completed = None
     self.filename = None
     self.flags = 0
     self.generation = 0
     self.page_size = 0
     self.oit = 0
     self.oat = 0
     self.ost = 0
     self.next_transaction = 0
     self.next_attachment_id = 0
     self.implementation = None
     self.shadow_count = 0
     self.page_buffers = 0
     self.next_header_page = 0
     self.database_dialect = 0
     self.creation_date = None
     self.attributes.clear()
     self.sweep_interval = None
     self.continuation_file = None
     self.last_logical_page = None
     self.backup_guid = None
     self.root_filename = None
     self.replay_logging_file = None
     self.backup_diff_file = None
     self.encrypted_data_pages = None
     self.encrypted_index_pages = None
     self.encrypted_blob_pages = None
     self.continuation_files.clear()
     self.__tables: DataList[StatTable] = DataList(type_spec=StatTable,
                                                   key_expr='item.name')
     self.__indices: DataList[StatIndex] = DataList(type_spec=StatIndex,
                                                    key_expr='item.name')
     #
     self.__line_no: int = 0
     self.__table: StatTable = None
     self.__index: StatIndex = None
     self.__new_block: bool = True
     self.__in_table: bool = False
     self.__step: int = 0
Exemple #11
0
    def test_find(self):
        i5 = self.data_items[4]
        l = DataList(self.data_items)
        result = l.find(lambda x: x.key >= 5)
        self.assertIsInstance(result, Item)
        self.assertEqual(result, i5)
        self.assertIsNone(l.find(lambda x: x.key > 100))
        self.assertEqual(l.find(lambda x: x.key > 100, 'DEFAULT'), 'DEFAULT')

        self.assertEqual(l.find('item.key >= 5'), i5)
        self.assertIsNone(l.find('item.key > 100'))
        self.assertEqual(l.find('item.key > 100', 'DEFAULT'), 'DEFAULT')
Exemple #12
0
 def callstack(self) -> DataList[CallStackInfo]:
     """List with complete call stack.
     """
     if self.__callstack is None:
         self.__callstack = DataList(
             (CallStackInfo(self, row)
              for row in self._select('select * from mon$call_stack')),
             CallStackInfo,
             'item.id',
             frozen=True)
     return self.__callstack
Exemple #13
0
 def statements(self) -> DataList[StatementInfo]:
     """List of all statements.
     """
     if self.__statements is None:
         self.__statements = DataList(
             (StatementInfo(self, row)
              for row in self._select('select * from mon$statements')),
             StatementInfo,
             'item.id',
             frozen=True)
     return self.__statements
Exemple #14
0
 def attachments(self) -> DataList[AttachmentInfo]:
     """List of all attachments.
     """
     if self.__attachments is None:
         self.__attachments = DataList(
             (AttachmentInfo(self, row)
              for row in self._select('select * from mon$attachments')),
             AttachmentInfo,
             'item.id',
             frozen=True)
     return self.__attachments
Exemple #15
0
 def transactions(self) -> DataList[TransactionInfo]:
     """List of all transactions.
     """
     if self.__transactions is None:
         self.__transactions = DataList(
             (TransactionInfo(self, row)
              for row in self._select('select * from mon$transactions')),
             TransactionInfo,
             'item.id',
             frozen=True)
     return self.__transactions
Exemple #16
0
 def test_extract(self):
     exp_return = [x for x in self.data_items if x.key > 5]
     exp_remains = [x for x in self.data_items if not x.key > 5]
     l = DataList(self.data_items)
     #
     result = l.extract(lambda x: x.key > 5)
     self.assertIsInstance(result, DataList)
     self.assertListEqual(result, exp_return)
     self.assertListEqual(l, exp_remains)
     self.assertEqual(len(result) + len(l), len(self.data_items))
     #
     l = DataList(self.data_items)
     result = l.extract('item.key > 5')
     self.assertListEqual(result, exp_return)
     self.assertListEqual(l, exp_remains)
     self.assertEqual(len(result) + len(l), len(self.data_items))
     # frozen
     with self.assertRaises(TypeError):
         l.freeze()
         l.extract('item.key > 5')
Exemple #17
0
 def variables(self) -> DataList[ContextVariableInfo]:
     """List of all context variables.
     """
     if self.__variables is None:
         self.__variables = DataList(
             (ContextVariableInfo(self, row)
              for row in self._select('select * from mon$context_variables')
              ),
             ContextVariableInfo,
             'item.stat_id',
             frozen=True)
     return self.__variables
Exemple #18
0
 def test_contains(self):
     # Simple
     l = DataList(self.data_items)
     self.assertTrue(l.contains('item.key >= 5'))
     self.assertTrue(l.contains(lambda x: x.key >= 5))
     self.assertFalse(l.contains('item.key > 100'))
     self.assertFalse(l.contains(lambda x: x.key > 100))
Exemple #19
0
    def tablestats(self) -> DataList[TableStatsInfo]:
        """List of all table record I/O statistics.
        """
        if self.__tablestats is None:
            cmd = """SELECT ts.MON$STAT_ID, ts.MON$STAT_GROUP, ts.MON$TABLE_NAME,
ts.MON$RECORD_STAT_ID, r.MON$RECORD_SEQ_READS, r.MON$RECORD_IDX_READS, r.MON$RECORD_INSERTS,
r.MON$RECORD_UPDATES, r.MON$RECORD_DELETES, r.MON$RECORD_BACKOUTS,
r.MON$RECORD_PURGES, r.MON$RECORD_EXPUNGES, r.MON$RECORD_LOCKS, r.MON$RECORD_WAITS,
r.MON$RECORD_CONFLICTS, r.MON$BACKVERSION_READS, r.MON$FRAGMENT_READS, r.MON$RECORD_RPT_READS
FROM MON$TABLE_STATS ts join MON$RECORD_STATS r
  on ts.MON$RECORD_STAT_ID = r.MON$STAT_ID"""
            self.__tablestats = DataList(
                (TableStatsInfo(self, row) for row in self._select(cmd)),
                TableStatsInfo,
                'item.stat_id',
                frozen=True)
        return self.__tablestats
Exemple #20
0
 def test_list_update(self):
     i1 = self.data_items[0]
     l = DataList(self.data_items)
     # Simple
     l[3] = i1
     self.assertEqual(l[3], i1)
     l = DataList(self.data_items, type_spec=Item)
     # With type_spec
     l[3] = i1
     self.assertEqual(l[3], i1)
     with self.assertRaises(TypeError, msg="With type_spec"):
         l[3] = self.data_desc[0]
     # With key expr
     l = DataList(self.data_items, key_expr=self.key_item)
     l[3] = i1
     self.assertEqual(l[3], i1)
     # Frozen
     with self.assertRaises(TypeError):
         l.freeze()
         l[3] = i1
Exemple #21
0
    def iostats(self) -> DataList[IOStatsInfo]:
        """List of all I/O statistics.
        """
        if self.__iostats is None:
            cmd = """SELECT r.MON$STAT_ID, r.MON$STAT_GROUP,
r.MON$RECORD_SEQ_READS, r.MON$RECORD_IDX_READS, r.MON$RECORD_INSERTS,
r.MON$RECORD_UPDATES, r.MON$RECORD_DELETES, r.MON$RECORD_BACKOUTS,
r.MON$RECORD_PURGES, r.MON$RECORD_EXPUNGES, r.MON$RECORD_LOCKS, r.MON$RECORD_WAITS,
r.MON$RECORD_CONFLICTS, r.MON$BACKVERSION_READS, r.MON$FRAGMENT_READS, r.MON$RECORD_RPT_READS,
io.MON$PAGE_FETCHES, io.MON$PAGE_MARKS, io.MON$PAGE_READS, io.MON$PAGE_WRITES,
m.MON$MEMORY_ALLOCATED, m.MON$MEMORY_USED, m.MON$MAX_MEMORY_ALLOCATED, m.MON$MAX_MEMORY_USED
FROM MON$RECORD_STATS r join MON$IO_STATS io
  on r.MON$STAT_ID = io.MON$STAT_ID and r.MON$STAT_GROUP = io.MON$STAT_GROUP
  join MON$MEMORY_USAGE m
  on r.MON$STAT_ID = m.MON$STAT_ID and r.MON$STAT_GROUP = m.MON$STAT_GROUP"""
            self.__iostats = DataList(
                (IOStatsInfo(self, row) for row in self._select(cmd)),
                IOStatsInfo,
                'item.stat_id',
                frozen=True)
        return self.__iostats
Exemple #22
0
 def test_get(self):
     i5 = self.data_items[4]
     # Simple
     l = DataList(self.data_items)
     with self.assertRaises(Error):
         l.get(i5.key)
     # Distinct type
     l = DataList(self.data_items, type_spec=Item)
     self.assertEqual(l.get(i5.key), i5)
     self.assertIsNone(l.get('NOT IN LIST'))
     self.assertEqual(l.get('NOT IN LIST', 'DEFAULT'), 'DEFAULT')
     # Key spec
     l = DataList(self.data_items, key_expr=self.key_item)
     self.assertEqual(l.get(i5.key), i5)
     self.assertIsNone(l.get('NOT IN LIST'))
     self.assertEqual(l.get('NOT IN LIST', 'DEFAULT'), 'DEFAULT')
     # Frozen (fast-path)
     #   with Distinct
     l = DataList(self.data_items, type_spec=Item, frozen=True)
     self.assertEqual(l.get(i5.key), i5)
     self.assertIsNone(l.get('NOT IN LIST'))
     self.assertEqual(l.get('NOT IN LIST', 'DEFAULT'), 'DEFAULT')
     #   with key_expr
     l = DataList(self.data_items, key_expr='item.key', frozen=True)
     self.assertEqual(l.get(i5.key), i5)
     self.assertIsNone(l.get('NOT IN LIST'))
     self.assertEqual(l.get('NOT IN LIST', 'DEFAULT'), 'DEFAULT')
Exemple #23
0
 def test_extend(self):
     l = DataList()
     # Simple
     l.extend(self.data_items)
     self.assertListEqual(l, self.data_items)
     # With type_spec
     l = DataList(type_spec=Item)
     l.extend(self.data_items)
     self.assertListEqual(l, self.data_items)
     with self.assertRaises(TypeError, msg="With type_spec"):
         l.extend(self.data_desc)
     # With key expr
     l = DataList(key_expr=self.key_item)
     l.extend(self.data_items)
     self.assertListEqual(l, self.data_items, "With key expr")
     # Frozen
     with self.assertRaises(TypeError):
         l.freeze()
         l.extend(self.data_items[0])
Exemple #24
0
 def test_in(self):
     # Simple
     l = DataList(self.data_items)
     self.assertTrue(self.data_items[0] in l)
     self.assertTrue(self.data_items[-1] in l)
     # Frozen
     l.freeze()
     self.assertTrue(self.data_items[0] in l)
     self.assertTrue(self.data_items[-1] in l)
     # Typed
     l = DataList(self.data_items, Item)
     self.assertTrue(self.data_items[0] in l)
     self.assertTrue(self.data_items[-1] in l)
     # Frozen
     l.freeze()
     self.assertTrue(self.data_items[0] in l)
     self.assertTrue(self.data_items[-1] in l)
     # Keyed
     l = DataList(self.data_items, key_expr='item.key')
     self.assertTrue(self.data_items[0] in l)
     self.assertTrue(self.data_items[-1] in l)
     # Frozen
     l.freeze()
     self.assertTrue(self.data_items[0] in l)
     self.assertTrue(self.data_items[-1] in l)
     nil = Item(100, "NOT IN LISTS")
     i5 = self.data_items[4]
     # Simple
     l = DataList(self.data_items)
     self.assertIn(i5, l)
     self.assertNotIn(nil, l)
     # Frozen distincts
     l = DataList(self.data_items, type_spec=Item, frozen=True)
     self.assertIn(i5, l)
     self.assertNotIn(nil, l)
     # Frozen key_expr
     l = DataList(self.data_items, key_expr=self.key_item, frozen=True)
     self.assertIn(i5, l)
     self.assertNotIn(nil, l)
Exemple #25
0
 def test_clear(self):
     l = DataList(self.data_items)
     #
     l.clear()
     self.assertListEqual(l, [])
Exemple #26
0
 def test_any(self):
     l = DataList(self.data_items)
     self.assertTrue(l.any(lambda x: '05' in x.name))
     self.assertFalse(l.any(lambda x: x.name.startswith('XXX')))
     self.assertTrue(l.any("'05' in item.name"))
     self.assertFalse(l.any("item.name.startswith('XXX')"))
Exemple #27
0
 def test_all(self):
     l = DataList(self.data_items)
     self.assertTrue(l.all(lambda x: x.name.startswith('Item')))
     self.assertFalse(l.all(lambda x: '1' in x.name))
     self.assertTrue(l.all("item.name.startswith('Item')"))
     self.assertFalse(l.all("'1' in item.name"))
Exemple #28
0
    def test_sort(self):
        i1, i2, i3 = self.data_items[:3]
        unsorted = [i3, i1, i2]
        l = DataList(unsorted)
        # Simple
        with self.assertRaises(TypeError):
            l.sort()
        if __debug__:
            with self.assertRaises(AssertionError):
                l.sort(attrs= 'key')
        l.sort(attrs=['key'])
        self.assertListEqual(l, [i1, i2, i3])
        l.sort(attrs=['key'], reverse=True)
        self.assertListEqual(l, [i3, i2, i1])

        l = DataList(unsorted)
        l.sort(expr=lambda x: x.key)
        self.assertListEqual(l, [i1, i2, i3])
        l.sort(expr=lambda x: x.key, reverse=True)
        self.assertListEqual(l, [i3, i2, i1])

        l = DataList(unsorted)
        l.sort(expr='item.key')
        self.assertListEqual(l, [i1, i2, i3])
        l.sort(expr='item.key', reverse=True)
        self.assertListEqual(l, [i3, i2, i1])
        # With key expr
        l = DataList(unsorted, key_expr=self.key_item)
        l.sort()
        self.assertListEqual(l, [i1, i2, i3])
        l.sort(reverse=True)
        self.assertListEqual(l, [i3, i2, i1])
Exemple #29
0
 def test_create(self):
     l = DataList()
     # Simple
     self.assertListEqual(l, [], "Simple")
     self.assertFalse(l.frozen, "Simple")
     self.assertIsNone(l.key_expr, "Simple")
     self.assertIs(l.type_spec, UNDEFINED, "Simple")
     # From items
     with self.assertRaises(TypeError):
         DataList(object)
     l = DataList(self.data_items)
     self.assertListEqual(l, self.data_items, "From items")
     self.assertFalse(l.frozen, "From items")
     self.assertIsNone(l.key_expr, "From items")
     self.assertIs(l.type_spec, UNDEFINED, "From items")
     # With type spec (Non-Distinct)
     l = DataList(type_spec=int)
     self.assertFalse(l.frozen, "With type spec (Non-Distinct)")
     self.assertIsNone(l.key_expr, "With type spec (Non-Distinct)")
     # With type spec (Distinct)
     l = DataList(type_spec=Item)
     self.assertFalse(l.frozen, "With type spec (Distinct)")
     self.assertEqual(l.key_expr, 'item.get_key()', "With type spec (Distinct)")
     self.assertEqual(l.type_spec, Item, "With type spec (Distinct)")
     l = DataList(type_spec=(Item, Desc))
     self.assertEqual(l.key_expr, 'item.get_key()', "With type spec (Distinct)")
     self.assertEqual(l.type_spec, (Item, Desc), "With type spec (Distinct)")
     # With key expr
     if __debug__:
         with self.assertRaises(AssertionError, msg="With key expr"):
             DataList(key_expr=object)
         with self.assertRaises(SyntaxError, msg="With key expr"):
             DataList(key_expr='wrong key expression')
     l = DataList(key_expr=self.key_item)
     self.assertFalse(l.frozen, "With key expr")
     self.assertEqual(l.key_expr, self.key_item, "With key expr")
     self.assertIs(l.type_spec, UNDEFINED, "With key expr")
     # With frozen
     l = DataList(frozen=True)
     self.assertTrue(l.frozen, "With frozen")
     # With all
     l = DataList(self.data_items, Item, self.key_item)
     self.assertEqual(l, self.data_items, "With all")
Exemple #30
0
 def test_reverse(self):
     revers = list(reversed(self.data_items))
     l = DataList(self.data_items)
     #
     l.reverse()
     self.assertListEqual(l, revers)