Ejemplo n.º 1
0
class StandardFieldTest(absltest.TestCase):

  def setUp(self):
    super().setUp()
    self.test_standard_field = StandardField(
        namespace_name='',
        standard_field_name='supply_air_flowrate_sensor',
        increment='_1_12')

  def testGetIncrement(self):
    expected_output = '_1_12'
    function_output = self.test_standard_field.GetIncrement()

    self.assertEqual(function_output, expected_output)

  def testGetNamespaceName(self):
    # testing with '' because it is the global namespace which, in practice,
    # all fields are defined under the global namespace
    expected_output = ''
    function_output = self.test_standard_field.GetNamespaceName()

    self.assertEqual(function_output, expected_output)

  def testGetStandardFieldName(self):
    expected_output = 'supply_air_flowrate_sensor'
    function_output = self.test_standard_field.GetStandardFieldName()

    self.assertEqual(function_output, expected_output)

  def testEqualityWithEntityTypeField(self):
    test_entity_type_field = EntityTypeField(
        namespace_name='',
        standard_field_name='supply_air_flowrate_sensor',
        is_optional=False,
        increment='_1_12')

    self.assertEqual(test_entity_type_field, self.test_standard_field)

  def testStandardFieldNameWithoutIncrement(self):
    test_unincremented_standard_field = StandardField(
        namespace_name='',
        standard_field_name='water_temperature_sensor'
    )

    self.assertEqual(
        test_unincremented_standard_field.GetStandardFieldName(),
        'water_temperature_sensor')

  def testIncorrectSFNRaisesValueError(self):
    # Standard field names cannot start with numbers
    incorrect_standard_field_name = '9lives_is_what_a_cat_has'
    with self.assertRaises(ValueError):
      StandardField(
          namespace_name='',
          standard_field_name=incorrect_standard_field_name,
          increment='_1'
      )
Ejemplo n.º 2
0
 def IsFieldValid(self, field: StandardField) -> bool:
   """A method to validate a field name against the ontology."""
   if not isinstance(field, StandardField):
     raise TypeError('Field argument must be a StandardField object.\n' +
                     f'You provided a {type(field)} object.')
   namespace_name = field.GetNamespaceName()
   standard_field_name = field.GetStandardFieldName()
   validity = self.universe.field_universe.IsFieldDefined(
       namespace_name=namespace_name, fieldname=standard_field_name)
   return validity
Ejemplo n.º 3
0
class StandardFieldTest(absltest.TestCase):

  def setUp(self):
    super(StandardFieldTest).setUp()
    self.test_standard_field = StandardField(
        namespace_name='', standard_field_name='supply_air_flowrate_sensor')

  def testGetNamespaceName(self):
    # testing with '' because it is the global namespace which, in practice,
    # all fields are defined under the global namespace
    expected_output = ''
    function_output = self.test_standard_field.GetNamespaceName()

    self.assertEqual(function_output, expected_output)

  def testGetStandardFieldName(self):
    expected_output = 'supply_air_flowrate_sensor'
    function_output = self.test_standard_field.GetStandardFieldName()

    self.assertEqual(function_output, expected_output)