Example #1
0
 def test_multipleContinuedStationControlHeader(self):
     """
     """
     # create a valid blockette 010 with record length 256
     b010 = b"0100042 2.4082008,001~2038,001~2009,001~~~"
     blockette = Blockette010(strict=True, compact=True)
     blockette.parseSEED(b010)
     self.assertEqual(b010, blockette.getSEED())
     # create a valid blockette 054
     b054 = b"0540960A0400300300000039"
     nr = b""
     for i in range(0, 78):
         # 960 chars
         nr = nr + ("+1.000%02dE-03" % i).encode('ascii', 'strict')
     blockette = Blockette054(strict=True, compact=True)
     blockette.parseSEED(b054 + nr)
     self.assertEqual(b054 + nr, blockette.getSEED())
     # create a blockette 051
     b051 = b'05100271999,123~~0001000000'
     blockette = Blockette051(strict=False)
     # ignore user warning
     with warnings.catch_warnings(record=True):
         warnings.simplefilter("ignore")
         blockette.parseSEED(b051)
     # combine data (each line equals 256 chars)
     data = b"000001V " + b010 + (b' ' * 206)
     data += b"000002S " + b054 + nr[0:224]  # 256-8-24 = 224
     data += b"000003S*" + nr[224:472]  # 256-8 = 248
     data += b"000004S*" + nr[472:720]
     data += b"000005S*" + nr[720:] + b051 + b' ' * 5  # 5 spaces left
     self.assertEqual(len(data), 256 * 5)
     data += b"000006S " + b054 + nr[0:224]  # 256-8-24 = 224
     data += b"000007S*" + nr[224:472]  # 256-8 = 248
     data += b"000008S*" + nr[472:720]
     data += b"000009S*" + nr[720:] + b' ' * 32  # 32 spaces left
     self.assertEqual(len(data), 256 * 9)
     # read records
     parser = Parser(strict=False)
     with warnings.catch_warnings():
         warnings.simplefilter("ignore")
         parser.read(data)
     # check results
     self.assertEqual(sorted(parser.blockettes.keys()), [10, 51, 54])
     self.assertEqual(len(parser.blockettes[10]), 1)
     self.assertEqual(len(parser.blockettes[51]), 1)
     self.assertEqual(len(parser.blockettes[54]), 2)
Example #2
0
 def test_blocketteStartsAfterRecord(self):
     """
     '... 058003504 1.00000E+00 0.00000E+0000 000006S*0543864 ... '
     ' 0543864' -> results in Blockette 005
     """
     # create a valid blockette 010 with record length 256
     b010 = "0100042 2.4082008,001~2038,001~2009,001~~~"
     blockette = Blockette010(strict=True, compact=True)
     blockette.parseSEED(b010)
     self.assertEquals(b010, blockette.getSEED())
     # create a valid blockette 054
     b054 = "0540240A0400300300000009" + ("+1.58748E-03" * 18)
     blockette = Blockette054(strict=True, compact=True)
     blockette.parseSEED(b054)
     self.assertEquals(b054, blockette.getSEED())
     # combine data
     data = "000001V " + b010 + (' ' * 206)
     data += "000002S " + b054 + (' ' * 8)
     data += "000003S*" + b054 + (' ' * 8)
     # read records
     parser = Parser(strict=True)
     parser.read(data)