Example #1
0
    def test_can_set_value_false(self):
        accessor = AttributeDataAccessor()
        obj = AttributeDummy('test_value')

        can_set = accessor.can_set_value(obj)

        self.assertFalse(can_set)
 def setUp(self):
     super().setUp()
     self.data = [
         DataItem(a=i, b=10*i, c=str(i)) for i in range(10)
     ]
     self.model = RowTableDataModel(
         data=self.data,
         row_header_data=AttributeDataAccessor(
             attr='a',
             value_type=IntValue(),
         ),
         column_data=[
             AttributeDataAccessor(
                 attr='b',
                 value_type=IntValue(),
             ),
             AttributeDataAccessor(
                 attr='c',
                 value_type=TextValue(),
             )
         ]
     )
     self.values_changed_event = None
     self.structure_changed_event = None
     self.model.observe(self.model_values_changed, 'values_changed')
     self.model.observe(self.model_structure_changed, 'structure_changed')
 def test_column_data_updated(self):
     with self.assertTraitChanges(self.model, "structure_changed"):
         self.model.column_data = [
             AttributeDataAccessor(
                 attr='c',
                 value_type=TextValue(),
             ),
             AttributeDataAccessor(
                 attr='b',
                 value_type=IntValue(),
             ),
         ]
     self.assertTrue(self.structure_changed_event.new)
Example #4
0
    def test_defaults(self):
        accessor = AttributeDataAccessor()

        self.assertEqual(accessor.attr, '')
        self.assertIsNone(accessor.value_type)
        self.assertIsInstance(accessor.title_type, TextValue)
        self.assertEqual(accessor.title, '')
 def test_row_header_data_updated(self):
     with self.assertTraitChanges(self.model, "values_changed"):
         self.model.row_header_data = AttributeDataAccessor(attr='b')
     self.assertEqual(
         self.values_changed_event.new,
         ((), (), (), ())
     )
    def test_no_data_column_data_update(self):
        model = RowTableDataModel(row_header_data=AttributeDataAccessor(
            attr='a',
            value_type=IntValue(),
        ),
                                  column_data=[
                                      AttributeDataAccessor(
                                          attr='b',
                                          value_type=IntValue(),
                                      ),
                                      AttributeDataAccessor(
                                          attr='c',
                                          value_type=TextValue(),
                                      )
                                  ])

        with self.assertTraitDoesNotChange(model, 'values_changed'):
            model.column_data[0].attr = 'a'
    def test_no_data_row_header_data_update(self):
        model = RowTableDataModel(row_header_data=AttributeDataAccessor(
            attr='a',
            value_type=IntValue(),
        ),
                                  column_data=[
                                      AttributeDataAccessor(
                                          attr='b',
                                          value_type=IntValue(),
                                      ),
                                      AttributeDataAccessor(
                                          attr='c',
                                          value_type=TextValue(),
                                      )
                                  ])

        # check that updating accessors is safe with empty data
        with self.assertTraitDoesNotChange(model, 'values_changed'):
            model.row_header_data.attr = 'b'
Example #8
0
    def test_set_value_error(self):
        accessor = AttributeDataAccessor()
        obj = AttributeDummy('test_value')

        with self.assertRaises(DataViewSetError):
            accessor.set_value(obj, 'new_value')
Example #9
0
 def create_accessor(self):
     return AttributeDataAccessor(
         attr='attr_value',
         value_type=TextValue(),
     )