예제 #1
0
def test_defaults():
    """Test defaults for units."""
    assert distance("10").value() == 10.0
    assert distance("1000").value("M") == 1000.0
    assert distance("1500").string() == "1500 meters"
    assert distance("1500", None).string() == "1500 meters"
    assert distance("5", "SM").string() == "5 miles"
예제 #2
0
def test_defaults():
    """Test defaults for units."""
    assert distance("10").value() == 10.0
    assert distance("1000").value("M") == 1000.0
    assert distance("1500").string() == "1500 meters"
    assert distance("1500", None).string() == "1500 meters"
    assert distance("5", "SM").string() == "5 miles"
예제 #3
0
    def _handleVisibility( self, d ):
        """
        Parse the minimum and maximum visibility groups.

        The following attributes are set:
            vis          [distance]
            vis_dir      [direction]
            max_vis      [distance]
            max_vis_dir  [direction]
        """
        vis = d['vis']
        vis_less = None
        vis_dir = None
        vis_units = "M"
        vis_dist = "10000"
        if d['dist'] and d['dist'] != '////':
            vis_dist = d['dist']
            if d['dir'] and d['dir'] != 'NDV':
                vis_dir = d['dir']
        elif d['distu']:
            vis_dist = d['distu']
            if d['units'] and d['units'] != "U":
                vis_units = d['units']
        if vis_dist == "9999":
            vis_dist = "10000"
            vis_less = ">"
        if self.vis:
            if vis_dir:
                self.max_vis_dir = direction(vis_dir)
            self.max_vis = distance(vis_dist, vis_units, vis_less)
        else:
            if vis_dir:
                self.vis_dir = direction(vis_dir)
            self.vis = distance(vis_dist, vis_units, vis_less)
예제 #4
0
    def _handleVisibility(self, d):
        """
        Parse the minimum and maximum visibility groups.

        The following attributes are set:
            vis          [distance]
            vis_dir      [direction]
            max_vis      [distance]
            max_vis_dir  [direction]
        """
        vis = d["vis"]
        vis_less = None
        vis_dir = None
        vis_units = "M"
        vis_dist = "10000"
        if d["dist"] and d["dist"] != "////":
            vis_dist = d["dist"]
            if d["dir"] and d["dir"] != "NDV":
                vis_dir = d["dir"]
        elif d["distu"]:
            vis_dist = d["distu"]
            if d["units"] and d["units"] != "U":
                vis_units = d["units"]
        if vis_dist == "9999":
            vis_dist = "10000"
            vis_less = ">"
        if self.vis:
            if vis_dir:
                self.max_vis_dir = direction(vis_dir)
            self.max_vis = distance(vis_dist, vis_units, vis_less)
        else:
            if vis_dir:
                self.vis_dir = direction(vis_dir)
            self.vis = distance(vis_dist, vis_units, vis_less)
예제 #5
0
    def _handleVisibility(self, d):
        """
        Parse the minimum and maximum visibility groups.

        The following attributes are set:
            vis          [distance]
            vis_dir      [direction]
            max_vis      [distance]
            max_vis_dir  [direction]
        """
        vis = d['vis']
        vis_less = None
        vis_dir = None
        vis_units = "M"
        vis_dist = "10000"
        if d['dist'] and d['dist'] != '////':
            vis_dist = d['dist']
            if d['dir'] and d['dir'] != 'NDV':
                vis_dir = d['dir']
        elif d['distu']:
            vis_dist = d['distu']
            if d['units'] and d['units'] != "U":
                vis_units = d['units']
        if vis_dist == "9999":
            vis_dist = "10000"
            vis_less = ">"
        if self.vis:
            if vis_dir:
                self.max_vis_dir = direction(vis_dir)
            self.max_vis = distance(vis_dist, vis_units, vis_less)
        else:
            if vis_dir:
                self.vis_dir = direction(vis_dir)
            self.vis = distance(vis_dist, vis_units, vis_less)
예제 #6
0
 def testErrorChecking(self):
     self.assertRaises(ValueError, distance, "10SM")
     self.assertRaises(ValueError, distance, "M1/2SM")
     self.assertRaises(ValueError, distance, "1000", "M", "=")
     self.assertRaises(ValueError, distance, "1000", "M", "gt")
     self.assertRaises(UnitsError, distance, "10", "NM")
     self.assertRaises(UnitsError, distance("1000").value, "furlongs")
     self.assertRaises(UnitsError, distance("500").string, "yards")
예제 #7
0
 def testErrorChecking(self):
   self.assertRaises( ValueError, distance, "10SM" )
   self.assertRaises( ValueError, distance, "M1/2SM" )
   self.assertRaises( ValueError, distance, "1000", "M", "=" )
   self.assertRaises( ValueError, distance, "1000", "M", "gt" )
   self.assertRaises( UnitsError, distance, "10", "NM" )
   self.assertRaises( UnitsError, distance("1000").value, "furlongs" )
   self.assertRaises( UnitsError, distance("500").string, "yards" )
예제 #8
0
 def testInputs(self):
     self.assertEqual(distance("10").value(), 10.0)
     self.assertEqual(distance(10).value(), 10.0)
     self.assertEqual(distance(10.0).value(), 10.0)
     self.assertEqual(distance(10.0, None).value(), 10.0)
     self.assertEqual(distance("1/2").value(), 0.5)
     self.assertEqual(distance("1 1/2").value(), 1.5)
     self.assertEqual(distance("11/2").value(), 1.5)
     self.assertEqual(distance("10", gtlt=">").value(), 10.0)
     self.assertEqual(distance("10", None, "<").value(), 10.0)
예제 #9
0
 def testInputs(self):
   self.assertEqual( distance("10").value(), 10.0 )
   self.assertEqual( distance(10).value(), 10.0 )
   self.assertEqual( distance(10.0).value(), 10.0 )
   self.assertEqual( distance(10.0, None).value(), 10.0 )
   self.assertEqual( distance("1/2").value(), 0.5 )
   self.assertEqual( distance("1 1/2").value(), 1.5 )
   self.assertEqual( distance("11/2").value(), 1.5 )
   self.assertEqual( distance("10", gtlt=">").value(), 10.0 )
   self.assertEqual( distance("10", None, "<").value(), 10.0 )
예제 #10
0
def test_inputs():
    """Test various inputs to distance(."""
    assert distance("10").value() == 10.0
    assert distance(10).value() == 10.0
    assert distance(10.0).value() == 10.0
    assert distance(10.0, None).value() == 10.0
    assert distance("1/2").value() == 0.5
    assert distance("1 1/2").value() == 1.5
    assert distance("11/2").value() == 1.5
    assert distance("10", gtlt=">").value() == 10.0
    assert distance("10", None, "<").value() == 10.0
예제 #11
0
def test_inputs():
    """Test various inputs to distance(."""
    assert distance("10").value() == 10.0
    assert distance(10).value() == 10.0
    assert distance(10.0).value() == 10.0
    assert distance(10.0, None).value() == 10.0
    assert distance("1/2").value() == 0.5
    assert distance("1 1/2").value() == 1.5
    assert distance("11/2").value() == 1.5
    assert distance("10", gtlt=">").value() == 10.0
    assert distance("10", None, "<").value() == 10.0
예제 #12
0
    def _handleSky(self, d):
        """
        Parse a sky-conditions group.

        The following attributes are set:
            sky        [list of tuples]
            .  cover   [string]
            .  height  [distance]
            .  cloud   [string]
        """
        height = d["height"]
        if not height or height == "///":
            height = None
        else:
            height = height.replace("O", "0")
            height = distance(int(height) * 100, "FT")
        cover = d["cover"]
        if cover == "SCK" or cover == "SKC" or cover == "CL":
            cover = "CLR"
        if cover == "0VC":
            cover = "OVC"
        cloud = d["cloud"]
        if cloud == "///":
            cloud = ""
        self.sky.append((cover, height, cloud))
예제 #13
0
    def _handleRunway(self, d):
        """
        Parse a runway visual range group.

        The following attributes are set:
            range   [list of tuples]
            . name  [string]
            . low   [distance]
            . high  [distance]
            . unit  [string]
        """
        if d["name"] is None:
            return
        unit = d["unit"] if d["unit"] is not None else "M"
        low = distance(d["low"], unit)
        if d["high"] is None:
            high = low
        else:
            high = distance(d["high"], unit)
        self.runway.append([d["name"], low, high, unit])
예제 #14
0
    def _handleRunway(self, d):
        """
        Parse a runway visual range group.

        The following attributes are set:
            range   [list of tuples]
            . name  [string]
            . low   [distance]
            . high  [distance]
            . unit  [string]
        """
        if d['name'] is None:
            return
        unit = d['unit'] if d['unit'] is not None else 'FT'
        low = distance(d['low'], unit)
        if d['high'] is None:
            high = low
        else:
            high = distance(d['high'], unit)
        self.runway.append([d['name'], low, high, unit])
예제 #15
0
    def _handleSky(self, d):
        """
        Parse a sky-conditions group.

        The following attributes are set:
            sky        [list of tuples]
            .  cover   [string]
            .  height  [distance]
            .  cloud   [string]
        """
        height = d['height']
        if not height or height == "///":
            height = None
        else:
            height = height.replace('O', '0')
            height = distance(int(height) * 100, "FT")
        cover = d['cover']
        if cover == 'SCK' or cover == 'SKC' or cover == 'CL': cover = 'CLR'
        if cover == '0VC': cover = 'OVC'
        cloud = d['cloud']
        if cloud == '///': cloud = ""
        self.sky.append((cover, height, cloud))
예제 #16
0
    def _handleSky( self, d ):
        """
        Parse a sky-conditions group.

        The following attributes are set:
            sky        [list of tuples]
            .  cover   [string]
            .  height  [distance]
            .  cloud   [string]
        """
        height = d['height']
        if not height or height == "///":
            height = None
        else:
            height = height.replace('O','0')
            height = distance(int(height)*100,"FT")
        cover = d['cover']
        if cover == 'SCK' or cover == 'SKC' or cover == 'CL': cover = 'CLR'
        if cover == '0VC': cover = 'OVC'
        cloud = d['cloud']
        if cloud == '///': cloud = ""
        self.sky.append((cover,height,cloud))
예제 #17
0
def test_conversions():
    """Test conversions."""
    assert distance("5", "SM").value("SM") == 5.0
    assert distance("5", "SM").value("MI") == 5.0
    assert abs(distance("5", "SM").value("M") - 8046.7) < 0.1
    assert abs(distance("5", "SM").value("KM") - 8.05) < 0.01
    assert abs(distance("5", "SM").value("FT") - 26400.0) < 0.1

    assert distance("5000", "M").value("M"), 5000.0
    assert distance("5000", "M").value("KM"), 5.0
    assert abs(distance("5000", "M").value("SM") - 3.1) < 0.1
    assert abs(distance("5000", "M").value("MI") - 3.1) < 0.1
    assert distance("5000", "M").value("FT") == 16404.2

    assert distance("5", "KM").value("KM") == 5.0
    assert distance("5", "KM").value("M") == 5000.0
    assert abs(distance("5", "KM").value("SM") - 3.1) < 0.1
    assert distance("5", "KM").value("FT") == 16404.2

    assert distance("5280", "FT").value("FT") == 5280.0
    assert abs(distance("5280", "FT").value("SM") - 1.0) < 0.00001
    assert abs(distance("5280", "FT").value("MI") - 1.0) < 0.00001
    assert abs(distance("5280", "FT").value("KM") - 1.609) < 0.001
    assert abs(distance("5280", "FT").value("M") - 1609.34) < 0.01

    assert abs(distance("1 1/2", "SM").value("FT") - 7920.0) < 0.01
    assert abs(distance("1/4", "SM").value("FT") - 1320.0) < 0.01

    assert abs(distance("10.5", "IN").value("M") - 0.27) < 0.01
    assert abs(distance("0.066", "KM").value("IN") - 2598.43) < 0.01

    assert distance("1 1/2", "SM").string("SM") == "1 1/2 miles"
    assert distance("3/16", "SM").string("SM") == "3/16 miles"
    assert distance("1/4", "SM").string("FT") == "1320 feet"
    assert distance("1/4", "SM", "<").string("SM") == "less than 1/4 miles"
    assert distance("5280", "FT").string("KM") == "1.6 km"
    assert distance(
        "10000", "M", ">").string("M") == "greater than 10000 meters"
예제 #18
0
 def _handleSnowDepthRemark(self, d):
     """
     Parse the 4/ group snowdepth report
     """
     self.snowdepth = distance(float(d["snowdepth"]), "IN")
     self._remarks.append(" snowdepth %s" % (self.snowdepth, ))
예제 #19
0
 def _handleSnowDepthRemark(self, d):
     """
     Parse the 4/ group snowdepth report
     """
     self.snowdepth = distance(float(d['snowdepth']), 'IN')
     self._remarks.append(" snowdepth %s" % (self.snowdepth, ))
예제 #20
0
  def testConversions(self):
    self.assertEqual( distance("5","SM").value("SM"), 5.0 )
    self.assertEqual( distance("5","SM").value("MI"), 5.0 )
    self.assertAlmostEqual( distance("5","SM").value("M"), 8046.7, 1 )
    self.assertAlmostEqual( distance("5","SM").value("KM"), 8.05, 2 )
    self.assertAlmostEqual( distance("5","SM").value("FT"), 26400.0, 1 )
 
    self.assertEqual( distance("5000","M").value("M"), 5000.0 )
    self.assertEqual( distance("5000","M").value("KM"), 5.0 )
    self.assertAlmostEqual( distance("5000","M").value("SM"), 3.1, 1 )
    self.assertAlmostEqual( distance("5000","M").value("MI"), 3.1, 1 )
    self.assertAlmostEqual( distance("5000","M").value("FT"), 16404.0, 0 )
 
    self.assertEqual( distance("5","KM").value("KM"), 5.0 )
    self.assertEqual( distance("5","KM").value("M"), 5000.0 )
    self.assertAlmostEqual( distance("5","KM").value("SM"), 3.1, 1 )
    self.assertAlmostEqual( distance("5","KM").value("FT"), 16404.0, 0 )
 
    self.assertEqual( distance("5280","FT").value("FT"), 5280.0 )
    self.assertAlmostEqual( distance("5280","FT").value("SM"), 1.0, 5 )
    self.assertAlmostEqual( distance("5280","FT").value("MI"), 1.0, 5 )
    self.assertAlmostEqual( distance("5280","FT").value("KM"), 1.609, 3 )
    self.assertAlmostEqual( distance("5280","FT").value("M"), 1609, 0 )
    
    self.assertAlmostEqual( distance("1 1/2","SM").value("FT"), 7920.0, 2 )
    self.assertAlmostEqual( distance("1/4","SM").value("FT"), 1320.0, 2 )
    
    self.assertEqual( distance("1 1/2","SM").string("SM"), "1 1/2 miles" )
    self.assertEqual( distance("3/16","SM").string("SM"), "3/16 miles" )
    self.assertEqual( distance("1/4","SM").string("FT"), "1320 feet" )
    self.assertEqual( distance("1/4","SM","<").string("SM"), "less than 1/4 miles" )
    self.assertEqual( distance("5280","FT").string("KM"), "1.6 km" )
    self.assertEqual( distance("10000","M",">").string("M"), "greater than 10000 meters" )
예제 #21
0
 def testDefaults(self):
   self.assertEqual( distance("10").value(), 10.0 )
   self.assertEqual( distance("1000").value("M"), 1000.0 )
   self.assertEqual( distance("1500").string(), "1500 meters" )
   self.assertEqual( distance("1500",None).string(), "1500 meters" )
   self.assertEqual( distance("5","SM").string(), "5 miles" )
예제 #22
0
def test_conversions():
    """Test conversions."""
    assert distance("5", "SM").value("SM") == 5.0
    assert distance("5", "SM").value("MI") == 5.0
    assert abs(distance("5", "SM").value("M") - 8046.7) < 0.1
    assert abs(distance("5", "SM").value("KM") - 8.05) < 0.01
    assert abs(distance("5", "SM").value("FT") - 26400.0) < 0.1

    assert distance("5000", "M").value("M"), 5000.0
    assert distance("5000", "M").value("KM"), 5.0
    assert abs(distance("5000", "M").value("SM") - 3.1) < 0.1
    assert abs(distance("5000", "M").value("MI") - 3.1) < 0.1
    assert distance("5000", "M").value("FT") == 16404.2

    assert distance("5", "KM").value("KM") == 5.0
    assert distance("5", "KM").value("M") == 5000.0
    assert abs(distance("5", "KM").value("SM") - 3.1) < 0.1
    assert distance("5", "KM").value("FT") == 16404.2

    assert distance("5280", "FT").value("FT") == 5280.0
    assert abs(distance("5280", "FT").value("SM") - 1.0) < 0.00001
    assert abs(distance("5280", "FT").value("MI") - 1.0) < 0.00001
    assert abs(distance("5280", "FT").value("KM") - 1.609) < 0.001
    assert abs(distance("5280", "FT").value("M") - 1609.34) < 0.01

    assert abs(distance("1 1/2", "SM").value("FT") - 7920.0) < 0.01
    assert abs(distance("1/4", "SM").value("FT") - 1320.0) < 0.01

    assert abs(distance("10.5", "IN").value("M") - 0.27) < 0.01
    assert abs(distance("0.066", "KM").value("IN") - 2598.43) < 0.01

    assert distance("1 1/2", "SM").string("SM") == "1 1/2 miles"
    assert distance("3/16", "SM").string("SM") == "3/16 miles"
    assert distance("1/4", "SM").string("FT") == "1320 feet"
    assert distance("1/4", "SM", "<").string("SM") == "less than 1/4 miles"
    assert distance("5280", "FT").string("KM") == "1.6 km"
    assert distance("10000", "M",
                    ">").string("M") == "greater than 10000 meters"
예제 #23
0
def test_error_checking():
    """Test exception raising."""
    with pytest.raises(ValueError):
        distance("10SM")
    with pytest.raises(ValueError):
        distance("M1/2SM")
    with pytest.raises(ValueError):
        distance("1000", "M", "=")
    with pytest.raises(ValueError):
        distance("1000", "M", "gt")
    with pytest.raises(UnitsError):
        distance("10", "NM")
    with pytest.raises(UnitsError):
        distance(distance("1000").value, "furlongs")
    with pytest.raises(UnitsError):
        distance(distance("500").string, "yards")
예제 #24
0
    def testConversions(self):
        self.assertEqual(distance("5", "SM").value("SM"), 5.0)
        self.assertEqual(distance("5", "SM").value("MI"), 5.0)
        self.assertAlmostEqual(distance("5", "SM").value("M"), 8046.7, 1)
        self.assertAlmostEqual(distance("5", "SM").value("KM"), 8.05, 2)
        self.assertAlmostEqual(distance("5", "SM").value("FT"), 26400.0, 1)

        self.assertEqual(distance("5000", "M").value("M"), 5000.0)
        self.assertEqual(distance("5000", "M").value("KM"), 5.0)
        self.assertAlmostEqual(distance("5000", "M").value("SM"), 3.1, 1)
        self.assertAlmostEqual(distance("5000", "M").value("MI"), 3.1, 1)
        self.assertAlmostEqual(distance("5000", "M").value("FT"), 16404.0, 0)

        self.assertEqual(distance("5", "KM").value("KM"), 5.0)
        self.assertEqual(distance("5", "KM").value("M"), 5000.0)
        self.assertAlmostEqual(distance("5", "KM").value("SM"), 3.1, 1)
        self.assertAlmostEqual(distance("5", "KM").value("FT"), 16404.0, 0)

        self.assertEqual(distance("5280", "FT").value("FT"), 5280.0)
        self.assertAlmostEqual(distance("5280", "FT").value("SM"), 1.0, 5)
        self.assertAlmostEqual(distance("5280", "FT").value("MI"), 1.0, 5)
        self.assertAlmostEqual(distance("5280", "FT").value("KM"), 1.609, 3)
        self.assertAlmostEqual(distance("5280", "FT").value("M"), 1609, 0)

        self.assertAlmostEqual(distance("1 1/2", "SM").value("FT"), 7920.0, 2)
        self.assertAlmostEqual(distance("1/4", "SM").value("FT"), 1320.0, 2)

        self.assertEqual(distance("1 1/2", "SM").string("SM"), "1 1/2 miles")
        self.assertEqual(distance("3/16", "SM").string("SM"), "3/16 miles")
        self.assertEqual(distance("1/4", "SM").string("FT"), "1320 feet")
        self.assertEqual(
            distance("1/4", "SM", "<").string("SM"), "less than 1/4 miles")
        self.assertEqual(distance("5280", "FT").string("KM"), "1.6 km")
        self.assertEqual(
            distance("10000", "M", ">").string("M"),
            "greater than 10000 meters")
예제 #25
0
def test_error_checking():
    """Test exception raising."""
    with pytest.raises(ValueError):
        distance("10SM")
    with pytest.raises(ValueError):
        distance("M1/2SM")
    with pytest.raises(ValueError):
        distance("1000", "M", "=")
    with pytest.raises(ValueError):
        distance("1000", "M", "gt")
    with pytest.raises(UnitsError):
        distance("10", "NM")
    with pytest.raises(UnitsError):
        distance(distance("1000").value, "furlongs")
    with pytest.raises(UnitsError):
        distance(distance("500").string, "yards")
예제 #26
0
 def testDefaults(self):
     self.assertEqual(distance("10").value(), 10.0)
     self.assertEqual(distance("1000").value("M"), 1000.0)
     self.assertEqual(distance("1500").string(), "1500 meters")
     self.assertEqual(distance("1500", None).string(), "1500 meters")
     self.assertEqual(distance("5", "SM").string(), "5 miles")