def test_GIVEN_db_with_good_unit_m_over_s_WHEN_called_return_no_failure( self): field = [Field('DESC', "Test description"), Field("EGU", "m/s")] records = [Record('ao', 'SHOULDPASS:MOVER', None, field)] dbs = Db('/path', records) failures = db_checks.get_units_valid(dbs) self.assertEqual(len(failures), 0)
def test_GIVEN_db_with_bad_unit_neg_square_pwr_WHEN_called_return_failure( self): field = [Field('DESC', "test prefer 1/m^2"), Field("EGU", "m^-2")] records = [Record('ao', 'SHOULDFAIL:NEGPOWER', None, field)] dbs = Db('/path', records) failures = db_checks.get_units_valid(dbs) self.assertNotEqual(len(failures), 0)
def test_GIVEN_db_with_invalid_units_WHEN_called_then_return_failure(self): fields = [Field('EGU', "BADUNIT")] records = [Record('ao', 'SHOULDFAIL:BADUNIT', None, fields)] dbs = Db('/path', records) failures = db_checks.get_units_valid(dbs) self.assertNotEqual(len(failures), 0)
def test_GIVEN_db_with_bad_unit_bits_kbytes_WHEN_called_return_failure( self): field = [ Field('DESC', "Test description"), Field("EGU", "bit kbyte^-1") ] records = [Record('ao', 'SHOULDFAIL:NEGPOWER', None, field)] dbs = Db('/path', records) failures = db_checks.get_units_valid(dbs) self.assertNotEqual(len(failures), 0)
def test_units_valid(self): """ This method loops through all found records and finds the unique units. It then checks these units are standard """ failures = db_checks.get_units_valid(self.db) self.assertEqual(len(failures), 0, msg=db_checks.build_failure_message( "Invalid units in {}".format(self.db.directory), failures))
def test_GIVEN_db_with_recognised_units_with_correct_syntax_WHEN_called_return_no_failure( self): field1 = [Field('DESC', "Test description"), Field("EGU", "cm")] field2 = [Field('DESC', "Test description"), Field("EGU", "m")] field3 = [Field('DESC', "Test description"), Field("EGU", "km")] field4 = [Field('DESC', "Test description"), Field("EGU", "kbyte")] field5 = [Field('DESC', "Test description"), Field("EGU", "bit/kbyte")] field6 = [Field('DESC', "Test description"), Field("EGU", "m/s")] field7 = [Field('DESC', "Test description"), Field("EGU", "m/(m s)")] field8 = [Field('DESC', "Test description"), Field("EGU", "1/cm")] field9 = [Field('DESC', "Test description"), Field("EGU", "cdeg")] field10 = [Field('DESC', "Test description"), Field("EGU", "cdeg/ss")] field11 = [ Field('DESC', "Newtons should be a valid EGU"), Field('EGU', "N") ] field12 = [ Field('DESC', "Should be able to prefix Newtons"), Field('EGU', "mN") ] records = [ Record('ao', 'SHOULDPASS:CM', None, field1), Record('ao', 'SHOULDPASS:M', None, field2), Record('ao', 'SHOULDPASS:KM', None, field3), Record('ao', 'SHOULDPASS:KBYTE', None, field4), Record('ao', 'SHOULDPASS:BITS_OVER_KBYTE', None, field5), Record('ao', 'SHOULDPASS:M_OVER_S', None, field6), Record('ao', 'SHOULDPASS:MM-1S-1', None, field7), Record('ao', 'SHOULDPASS:1_OVER', None, field8), Record('ao', 'SHOULDPASS:CDEG', None, field9), Record('ao', 'SHOULDPASS:CDEG_OVER_SS', None, field10), Record('ao', 'SHOULDPASS:NEWTONS:N', None, field11), Record('ao', '"SHOULDPASS:MILINEWTONS', None, field12), ] dbs = Db('/path', records) failures = db_checks.get_units_valid(dbs) self.assertEqual(len(failures), 0)
def test_GIVEN_db_with_bad_unit_MA_1S_1_WHEN_called_return_failure(self): field = [Field('DESC', "Test description"), Field("EGU", "m/(As)")] records = [Record('ao', 'SHOULDFAIL:BADUNIT', None, field)] dbs = Db('/path', records) failures = db_checks.get_units_valid(dbs) self.assertNotEqual(len(failures), 0)