コード例 #1
0
ファイル: test_pvl.py プロジェクト: jessemapel/pvl
def test_comments():
    some_pvl = ("""
        /* comment on line */
        # here is a line comment
        /* here is a multi-
        line comment */
        foo = bar /* comment at end of line */
        weird/* in the */=/*middle*/comments
        baz = bang # end line comment
        End
    """)

    # Strict PVL doesn't allow #-comments
    with pytest.raises(pvl.lexer.LexerError):
        pvl.loads(some_pvl, grammar=pvl.grammar.PVLGrammar())

    # But the OmniGrammar does:
    label = pvl.loads(some_pvl)

    assert len(label) == 3

    assert isinstance(label['foo'], str)
    assert label['foo'] == 'bar'

    assert isinstance(label['foo'], str)
    assert label['weird'] == 'comments'

    assert isinstance(label['foo'], str)
    assert label['baz'] == 'bang'

    with pytest.raises(pvl.lexer.LexerError):
        pvl.loads(b'/*')
コード例 #2
0
ファイル: test_decoder.py プロジェクト: michaelaye/pvl
def test_units():
    label = pvl.loads("""
        foo = 42 <beards>
        g = 9.8 <m/s>
        list = (1, 2, 3) <numbers>
        cool = (1 <number>)
        End
    """)
    assert isinstance(label['foo'], Units)
    assert label['foo'].value == 42
    assert label['foo'].units == 'beards'

    assert isinstance(label['g'], Units)
    assert label['g'].value == 9.8
    assert label['g'].units == 'm/s'

    assert isinstance(label['list'], Units)
    assert isinstance(label['list'].value, list)
    assert label['list'].units == 'numbers'

    assert isinstance(label['cool'], list)
    assert isinstance(label['cool'][0], Units)
    assert label['cool'][0].value == 1
    assert label['cool'][0].units == 'number'

    with pytest.raises(pvl.decoder.ParseError):
        pvl.loads(b'foo = bar <')
コード例 #3
0
ファイル: test_decoder.py プロジェクト: cmillion/pvl
def test_groups():
    label = pvl.loads("""
        Group = test_group
          foo = bar
          Object = embedded_object
            foo = bar
          End_Object

          Group = embedded_group
            foo = bar
          End_Group
        End_Group
        End
    """)
    test_group = label['test_group']
    assert isinstance(test_group, LabelGroup)
    assert test_group['foo'] == 'bar'

    embedded_object = test_group['embedded_object']
    assert isinstance(embedded_object, LabelObject)
    assert embedded_object['foo'] == 'bar'

    embedded_group = test_group['embedded_group']
    assert isinstance(embedded_group, LabelGroup)
    assert embedded_group['foo'] == 'bar'

    with pytest.raises(pvl.decoder.ParseError):
        pvl.loads("""
            BEGIN_GROUP = foo
            END_GROUP = bar
        """)
コード例 #4
0
ファイル: test_decoder.py プロジェクト: cmillion/pvl
def test_comments():
    label = pvl.loads("""
        /* comment on line */
        # here is a line comment
        /* here is a multi-
        line comment */
        foo = bar /* comment at end of line */
        weird/* in the */=/*middle*/comments
        baz = bang # end line comment
        End
    """)

    assert len(label) == 3

    assert isinstance(label['foo'], six.text_type)
    assert label['foo'] == 'bar'

    assert isinstance(label['foo'], six.text_type)
    assert label['weird'] == 'comments'

    assert isinstance(label['foo'], six.text_type)
    assert label['baz'] == 'bang'

    with pytest.raises(pvl.decoder.ParseError):
        pvl.loads(b'/*')
コード例 #5
0
def test_units():
    label = pvl.loads("""
        foo = 42 <beards>
        g = 9.8 <m/s>
        list = (1, 2, 3) <numbers>
        cool = (1 <number>)
        End
    """)
    assert isinstance(label["foo"], Quantity)
    assert label["foo"].value == 42
    assert label["foo"].units == "beards"

    assert isinstance(label["g"], Quantity)
    assert label["g"].value == 9.8
    assert label["g"].units == "m/s"

    assert isinstance(label["list"], Quantity)
    assert isinstance(label["list"].value, list)
    assert label["list"].units == "numbers"

    assert isinstance(label["cool"], list)
    assert isinstance(label["cool"][0], Quantity)
    assert label["cool"][0].value == 1
    assert label["cool"][0].units == "number"

    with pytest.raises(LexerError):
        pvl.loads(b"foo = bar <")
コード例 #6
0
def test_comments():
    some_pvl = """
        /* comment on line */
        # here is a line comment
        /* here is a multi-
        line comment */
        foo = bar /* comment at end of line */
        weird/* in the */=/*middle*/comments
        baz = bang # end line comment
        End
    """

    # Strict PVL doesn't allow #-comments
    with pytest.raises(LexerError):
        pvl.loads(some_pvl, grammar=pvl.grammar.PVLGrammar())

    # But the OmniGrammar does:
    label = pvl.loads(some_pvl)

    assert len(label) == 3

    assert isinstance(label["foo"], str)
    assert label["foo"] == "bar"

    assert isinstance(label["foo"], str)
    assert label["weird"] == "comments"

    assert isinstance(label["foo"], str)
    assert label["baz"] == "bang"

    with pytest.raises(LexerError):
        pvl.loads(b"/*")
コード例 #7
0
ファイル: test_pvl.py プロジェクト: jessemapel/pvl
def test_objects():
    label = pvl.loads("""
        Object = test_object
          foo = bar

          Object = embedded_object
            foo = bar
          End_Object

          Group = embedded_group
            foo = bar
          End_Group
        End_Object
        End
    """)
    test_object = label['test_object']
    assert isinstance(test_object, LabelObject)
    assert test_object['foo'] == 'bar'

    embedded_object = test_object['embedded_object']
    assert isinstance(embedded_object, LabelObject)
    assert embedded_object['foo'] == 'bar'

    embedded_group = test_object['embedded_group']
    assert isinstance(embedded_group, LabelGroup)
    assert embedded_group['foo'] == 'bar'

    with pytest.raises(pvl.lexer.LexerError):
        pvl.loads("""
            BEGIN_OBJECT = foo
            END_OBJECT = bar
        """)
コード例 #8
0
ファイル: test_decoder.py プロジェクト: michaelaye/pvl
def test_groups():
    label = pvl.loads("""
        Group = test_group
          foo = bar
          Object = embedded_object
            foo = bar
          End_Object

          Group = embedded_group
            foo = bar
          End_Group
        End_Group
        End
    """)
    test_group = label['test_group']
    assert isinstance(test_group, LabelGroup)
    assert test_group['foo'] == 'bar'

    embedded_object = test_group['embedded_object']
    assert isinstance(embedded_object, LabelObject)
    assert embedded_object['foo'] == 'bar'

    embedded_group = test_group['embedded_group']
    assert isinstance(embedded_group, LabelGroup)
    assert embedded_group['foo'] == 'bar'

    with pytest.raises(pvl.decoder.ParseError):
        pvl.loads("""
            BEGIN_GROUP = foo
            END_GROUP = bar
        """)
コード例 #9
0
ファイル: test_decoder.py プロジェクト: cmillion/pvl
def test_units():
    label = pvl.loads("""
        foo = 42 <beards>
        g = 9.8 <m/s>
        list = (1, 2, 3) <numbers>
        cool = (1 <number>)
        End
    """)
    assert isinstance(label['foo'], Units)
    assert label['foo'].value == 42
    assert label['foo'].units == 'beards'

    assert isinstance(label['g'], Units)
    assert label['g'].value == 9.8
    assert label['g'].units == 'm/s'

    assert isinstance(label['list'], Units)
    assert isinstance(label['list'].value, list)
    assert label['list'].units == 'numbers'

    assert isinstance(label['cool'], list)
    assert isinstance(label['cool'][0], Units)
    assert label['cool'][0].value == 1
    assert label['cool'][0].units == 'number'

    with pytest.raises(pvl.decoder.ParseError):
        pvl.loads(b'foo = bar <')
コード例 #10
0
def test_groups():
    label = pvl.loads("""
        Group = test_group
          foo = bar
          Object = embedded_object
            foo = bar
          End_Object

          Group = embedded_group
            foo = bar
          End_Group
        End_Group
        End
    """)
    test_group = label["test_group"]
    assert isinstance(test_group, LabelGroup)
    assert test_group["foo"] == "bar"

    embedded_object = test_group["embedded_object"]
    assert isinstance(embedded_object, LabelObject)
    assert embedded_object["foo"] == "bar"

    embedded_group = test_group["embedded_group"]
    assert isinstance(embedded_group, LabelGroup)
    assert embedded_group["foo"] == "bar"

    with pytest.raises(LexerError):
        pvl.loads("""
            BEGIN_GROUP = foo
            END_GROUP = bar
        """)
コード例 #11
0
ファイル: test_decoder.py プロジェクト: michaelaye/pvl
def test_comments():
    label = pvl.loads("""
        /* comment on line */
        # here is a line comment
        /* here is a multi-
        line comment */
        foo = bar /* comment at end of line */
        weird/* in the */=/*middle*/comments
        baz = bang # end line comment
        End
    """)

    assert len(label) == 3

    assert isinstance(label['foo'], six.text_type)
    assert label['foo'] == 'bar'

    assert isinstance(label['foo'], six.text_type)
    assert label['weird'] == 'comments'

    assert isinstance(label['foo'], six.text_type)
    assert label['baz'] == 'bang'

    with pytest.raises(pvl.decoder.ParseError):
        pvl.loads(b'/*')
コード例 #12
0
ファイル: HiccdStitch.py プロジェクト: SchallerSpace/hiproc
def get_stats(cubes: list) -> list:
    for i, c in enumerate(cubes):
        cubes[i].lstats = float(
            pvl.loads(isis.stats(c.lm_path).stdout)["Results"]["Average"])
        cubes[i].rstats = float(
            pvl.loads(isis.stats(c.rm_path).stdout)["Results"]["Average"])

    return cubes
コード例 #13
0
ファイル: test_decoder.py プロジェクト: jlaura/pvl
def test_assignment():
    label = pvl.loads('foo=bar')
    assert isinstance(label, Label)
    assert label['foo'] == 'bar'

    label = pvl.loads('Group_Foo=bar')
    assert isinstance(label, Label)
    assert label['Group_Foo'] == 'bar'
コード例 #14
0
ファイル: test_init.py プロジェクト: michaelaye/pvl
    def test_loads(self):
        some_pvl = """
a = b
GROUP = c
    c = d
END_GROUP
e =false
END"""
        decoded = pvl.PVLModule(a="b", c=pvl.PVLGroup(c="d"), e=False)
        self.assertEqual(decoded, pvl.loads(some_pvl))

        self.assertEqual(pvl.PVLModule(a="b"), pvl.loads("a=b"))
コード例 #15
0
ファイル: test_init.py プロジェクト: jessemapel/pvl
    def test_loads(self):
        some_pvl = '''
a = b
GROUP = c
    c = d
END_GROUP
e =false
END'''
        decoded = pvl.PVLModule(a='b', c=pvl.PVLGroup(c='d'), e=False)
        self.assertEqual(decoded, pvl.loads(some_pvl))

        self.assertEqual(pvl.PVLModule(a='b'), pvl.loads('a=b'))
コード例 #16
0
ファイル: test_encoder.py プロジェクト: planetarypy/pvl
def test_special_values():
    module = pvl.PVLModule([
        ('bool_true', True),
        ('bool_false', False),
        ('null', None),
    ])
    assert module == pvl.loads(pvl.dumps(module))

    encoder = pvl.encoder.IsisCubeLabelEncoder
    assert module == pvl.loads(pvl.dumps(module, cls=encoder))

    encoder = pvl.encoder.PDSLabelEncoder
    assert module == pvl.loads(pvl.dumps(module, cls=encoder))
コード例 #17
0
ファイル: test_encoder.py プロジェクト: planetarypy/pvl
def test_special_strings():
    module = pvl.PVLModule([
        ('single_quote', "'"),
        ('double_quote', '"'),
        ('mixed_quotes', '"\''),
    ])
    assert module == pvl.loads(pvl.dumps(module))

    encoder = pvl.encoder.IsisCubeLabelEncoder
    assert module == pvl.loads(pvl.dumps(module, cls=encoder))

    encoder = pvl.encoder.PDSLabelEncoder
    assert module == pvl.loads(pvl.dumps(module, cls=encoder))
コード例 #18
0
def test_special_strings():
    module = pvl.PVLModule([
        ('single_quote', "'"),
        ('double_quote', '"'),
        ('mixed_quotes', '"\''),
    ])
    assert module == pvl.loads(pvl.dumps(module))

    encoder = pvl.encoder.IsisCubeLabelEncoder
    assert module == pvl.loads(pvl.dumps(module, cls=encoder))

    encoder = pvl.encoder.PDSLabelEncoder
    assert module == pvl.loads(pvl.dumps(module, cls=encoder))
コード例 #19
0
def test_special_values():
    module = pvl.PVLModule([
        ('bool_true', True),
        ('bool_false', False),
        ('null', None),
    ])
    assert module == pvl.loads(pvl.dumps(module))

    encoder = pvl.encoder.IsisCubeLabelEncoder
    assert module == pvl.loads(pvl.dumps(module, cls=encoder))

    encoder = pvl.encoder.PDSLabelEncoder
    assert module == pvl.loads(pvl.dumps(module, cls=encoder))
コード例 #20
0
def crop_latlon(*,
                center_lat: float,
                center_lon: float,
                nsamples,
                nlines,
                to_cube,
                from_cube,
                pad=None,
                failed_list_to=None):
    print('cropping {}'.format(from_cube))
    try:
        center_campt = pvl.loads(
            campt(from_=from_cube,
                  type="ground",
                  latitude=center_lat,
                  longitude=center_lon))
        catlab_data = pvl.loads(catlab(from_=from_cube))

    except ProcessError as e:
        print(e.stderr, e.stdout)

    center_pixel = (center_campt['GroundPoint']['Line'],
                    center_campt['GroundPoint']['Sample'])

    #If user asked for max width, start at left edge
    if nsamples == 'max':
        nw_pixel = [center_pixel[0] - int(nlines) / 2, 1]
        nsamples = int(
            catlab_data['IsisCube']['Core']['Dimensions']['Samples'])
    else:
        nw_pixel = [
            center_pixel[0] - int(nlines) / 2,
            center_pixel[1] - int(nsamples) / 2
        ]

    try:
        print("sample:{} line:{}".format(nw_pixel[1], nw_pixel[0]))
        crop(from_=from_cube,
             sample=int(nw_pixel[1]),
             line=int(nw_pixel[0]),
             nsamples=nsamples,
             nlines=nlines,
             to=to_cube)
    except ProcessError as e:
        print(e.stderr, e.stdout)
        if failed_list_to:
            with open(failed_list_to, 'a') as failed_list:
                failed_list.write(' {}, {} \n'.format(from_cube, e.stderr))
コード例 #21
0
    def label(self):
        """
        Loads a PVL from from the _file attribute and
        parses the binary table data.

        Returns
        -------
        PVLModule :
            Dict-like object with PVL keys
        """
        class PvlDecoder(pvl.decoder.PVLDecoder):
            def unescape_next_char(self, stream):
                esc = stream.read(1)
                string = '\{}'.format(esc.decode('utf-8')).encode('utf-8')
                return string

        if not hasattr(self, "_label"):
            if isinstance(self._file, pvl.PVLModule):
                self._label = self._file
            try:
                self._label = pvl.loads(self._file, PvlDecoder)
            except Exception:

                # PvlDecoder class to ignore all escape sequences when getting
                # the label
                self._label = pvl.load(self._file, PvlDecoder)
            except:
                raise ValueError("{} is not a valid label".format(self._file))
        return self._label
コード例 #22
0
def test_floats():
    label = pvl.loads("""
        float = 1.0
        float_no_decimal = 2.
        float_no_whole = .3
        float_leading_zero = 0.5
        positive_float = +2.0
        negative_float = -1.0
        invalid_float = 1.2.3
        End
    """)
    assert isinstance(label["float"], float)
    assert label["float"] == 1.0

    assert isinstance(label["float_no_decimal"], float)
    assert label["float_no_decimal"] == 2.0

    assert isinstance(label["float_no_whole"], float)
    assert label["float_no_whole"] == 0.3

    assert isinstance(label["float_leading_zero"], float)
    assert label["float_leading_zero"] == 0.5

    assert isinstance(label["positive_float"], float)
    assert label["positive_float"] == 2.0

    assert isinstance(label["negative_float"], float)
    assert label["negative_float"] == -1.0

    assert isinstance(label["invalid_float"], str)
    assert label["invalid_float"] == "1.2.3"
コード例 #23
0
ファイル: test_decoder.py プロジェクト: michaelaye/pvl
def test_floats():
    label = pvl.loads("""
        float = 1.0
        float_no_decimal = 2.
        float_no_whole = .3
        float_leading_zero = 0.5
        positive_float = +2.0
        negative_float = -1.0
        invalid_float = 1.2.3
        End
    """)
    assert isinstance(label['float'], float)
    assert label['float'] == 1.0

    assert isinstance(label['float_no_decimal'], float)
    assert label['float_no_decimal'] == 2.0

    assert isinstance(label['float_no_whole'], float)
    assert label['float_no_whole'] == 0.3

    assert isinstance(label['float_leading_zero'], float)
    assert label['float_leading_zero'] == 0.5

    assert isinstance(label['positive_float'], float)
    assert label['positive_float'] == 2.0

    assert isinstance(label['negative_float'], float)
    assert label['negative_float'] == -1.0

    assert isinstance(label['invalid_float'], six.text_type)
    assert label['invalid_float'] == '1.2.3'
コード例 #24
0
ファイル: test_decoder.py プロジェクト: cmillion/pvl
def test_assignment():
    label = pvl.loads('foo=bar')
    assert isinstance(label, Label)
    assert label['foo'] == 'bar'

    label = pvl.loads('Group_Foo=bar')
    assert isinstance(label, Label)
    assert label['Group_Foo'] == 'bar'

    label = pvl.loads('foo=bar-')
    assert isinstance(label, Label)
    assert label['foo'] == 'bar-'

    label = pvl.loads('foo=bar-\n')
    assert isinstance(label, Label)
    assert label['foo'] == 'bar-'
コード例 #25
0
ファイル: test_decoder.py プロジェクト: jlaura/pvl
def test_groups():
    label = pvl.loads("""
        Group = test_group
          foo = bar
          Object = embedded_object
            foo = bar
          End_Object

          Group = embedded_group
            foo = bar
          End_Group
        End_Group
        End
    """)
    test_group = label['test_group']
    assert isinstance(test_group, LabelGroup)
    assert test_group['foo'] == 'bar'

    embedded_object = test_group['embedded_object']
    assert isinstance(embedded_object, LabelObject)
    assert embedded_object['foo'] == 'bar'

    embedded_group = test_group['embedded_group']
    assert isinstance(embedded_group, LabelGroup)
    assert embedded_group['foo'] == 'bar'
コード例 #26
0
ファイル: test_decoder.py プロジェクト: cmillion/pvl
def test_floats():
    label = pvl.loads("""
        float = 1.0
        float_no_decimal = 2.
        float_no_whole = .3
        float_leading_zero = 0.5
        positive_float = +2.0
        negative_float = -1.0
        invalid_float = 1.2.3
        End
    """)
    assert isinstance(label['float'], float)
    assert label['float'] == 1.0

    assert isinstance(label['float_no_decimal'], float)
    assert label['float_no_decimal'] == 2.0

    assert isinstance(label['float_no_whole'], float)
    assert label['float_no_whole'] == 0.3

    assert isinstance(label['float_leading_zero'], float)
    assert label['float_leading_zero'] == 0.5

    assert isinstance(label['positive_float'], float)
    assert label['positive_float'] == 2.0

    assert isinstance(label['negative_float'], float)
    assert label['negative_float'] == -1.0

    assert isinstance(label['invalid_float'], six.text_type)
    assert label['invalid_float'] == '1.2.3'
コード例 #27
0
def parse_label(label, grammar=pvl.grammar.PVLGrammar):
    """
    Attempt to parse a PVL label.

    Parameters
    ----------
    label
        The label as a pvl string or pvl file.

    grammar
        The pvl grammar with which to parse the label. If None, default to PVLGrammar


    Returns
    -------
    pvl.collections.PVLModule
        The PVL label deserialized to a Python object

    See Also
    --------
    load
    loads
    """
    try:
        parsed_label = pvl.loads(label, grammar=grammar)
    except Exception:
        parsed_label = pvl.load(label, grammar=grammar)
    except:
        raise ValueError("{} is not a valid label for grammar {}".format(label, grammar.__name__))

    return parsed_label
コード例 #28
0
ファイル: pvl_validate.py プロジェクト: michaelaye/pvl
def pvl_flavor(
    text, dialect, decenc: dict, filename, verbose=False
) -> tuple((bool, bool)):
    """Returns a two-tuple of booleans which indicate
    whether the *text* could be loaded and then encoded.

    The first boolean in the two-tuple indicates whether the *text*
    could be loaded with the given parser, grammar, and decoder.
    The second indicates whether the loaded PVL object could be
    encoded with the given encoder, grammar, and decoder.  If the
    first element is False, the second will be None.
    """
    loads = None
    encodes = None
    try:
        some_pvl = pvl.loads(text, **decenc)
        loads = True

        try:
            pvl.dumps(some_pvl, **decenc)
            encodes = True
        except (LexerError, ParseError, ValueError) as err:
            logging.error(f"{dialect} encode error {filename} {err}")
            encodes = False
    except (LexerError, ParseError) as err:
        logging.error(f"{dialect} load error {filename} {err}")
        loads = False

    return (loads, encodes)
コード例 #29
0
ファイル: test_decoder.py プロジェクト: michaelaye/pvl
def test_dates():
    label = pvl.loads("""
        date1          = 1990-07-04
        date2          = 1990-158
        date3          = 2001-001
        time1          = 12:00
        time_s         = 12:00:45
        time_s_float   = 12:00:45.4571
        time_tz1       = 15:24:12Z
        time_tz2       = 01:12:22+07
        time_tz3       = 01:12:22+7
        time_tz4       = 01:10:39.4575+07
        datetime1      = 1990-07-04T12:00
        datetime2      = 1990-158T15:24:12Z
        datetime3      = 2001-001T01:10:39+7
        datetime4      = 2001-001T01:10:39.457591+7
        End
    """)

    assert isinstance(label['date1'], datetime.date)
    assert label['date1'] == datetime.date(1990, 7, 4)

    assert isinstance(label['date2'], datetime.date)
    assert label['date2'] == datetime.date(1990, 6, 7)

    assert isinstance(label['date3'], datetime.date)
    assert label['date3'] == datetime.date(2001, 1, 1)

    assert isinstance(label['time1'], datetime.time)
    assert label['time1'] == datetime.time(12)

    assert isinstance(label['time_s'], datetime.time)
    assert label['time_s'] == datetime.time(12, 0, 45)

    assert isinstance(label['time_s_float'], datetime.time)
    assert label['time_s_float'] == datetime.time(12, 0, 45, 457100)

    assert isinstance(label['time_tz1'], datetime.time)
    assert label['time_tz1'] == datetime.time(15, 24, 12, tzinfo=pytz.utc)

    assert isinstance(label['time_tz2'], datetime.time)
    assert label['time_tz2'] == datetime.time(1, 12, 22, tzinfo=pytz.FixedOffset(420))  # noqa

    assert isinstance(label['time_tz3'], datetime.time)
    assert label['time_tz3'] == datetime.time(1, 12, 22, tzinfo=pytz.FixedOffset(420))  # noqa

    assert isinstance(label['time_tz4'], datetime.time)
    assert label['time_tz4'] == datetime.time(1, 10, 39, 457500, pytz.FixedOffset(420))  # noqa

    assert isinstance(label['datetime1'], datetime.datetime)
    assert label['datetime1'] == datetime.datetime(1990, 7, 4, 12)

    assert isinstance(label['datetime2'], datetime.datetime)
    assert label['datetime2'] == datetime.datetime(1990, 6, 7, 15, 24, 12, tzinfo=pytz.utc)  # noqa

    assert isinstance(label['datetime3'], datetime.datetime)
    assert label['datetime3'] == datetime.datetime(2001, 1, 1, 1, 10, 39, tzinfo=pytz.FixedOffset(420))  # noqa

    assert isinstance(label['datetime4'], datetime.datetime)
    assert label['datetime4'] == datetime.datetime(2001, 1, 1, 1, 10, 39, 457591, pytz.FixedOffset(420))  # noqa
コード例 #30
0
def test_linewrap():
    label = pvl.loads("""
        foo = bar-
              baz
        End
    """)

    assert label["foo"] == "barbaz"
コード例 #31
0
ファイル: test_decoder.py プロジェクト: cmillion/pvl
def test_linewrap():
    label = pvl.loads("""
        foo = bar-
              baz
        End
    """)

    assert label['foo'] == 'barbaz'
コード例 #32
0
ファイル: test_decoder.py プロジェクト: michaelaye/pvl
def test_linewrap():
    label = pvl.loads("""
        foo = bar-
              baz
        End
    """)

    assert label['foo'] == 'barbaz'
コード例 #33
0
def test_special_strings():
    module = pvl.PVLModule([
        ("single_quote", "'"),
        ("double_quote", '"'),
        # ('mixed_quotes', '"\''),  # see above about escaped quotes.
    ])
    assert module == pvl.loads(
        pvl.dumps(module, encoder=pvl.encoder.PVLEncoder()))
コード例 #34
0
ファイル: test_decoder.py プロジェクト: michaelaye/pvl
def test_hex():
    label = pvl.loads("""
        hex_number_upper = 16#100A#
        hex_number_lower = 16#100b#
        positive_hex_number = +16#100A#
        negative_hex_number = -16#100A#
        End
    """)

    assert isinstance(label['hex_number_upper'], int)
    assert label['hex_number_upper'] == 4106

    assert isinstance(label['hex_number_lower'], int)
    assert label['hex_number_lower'] == 4107

    assert isinstance(label['positive_hex_number'], int)
    assert label['positive_hex_number'] == 4106

    assert isinstance(label['negative_hex_number'], int)
    assert label['negative_hex_number'] == -4106

    with pytest.raises(pvl.decoder.ParseError):
        pvl.loads('empty = 16##')

    with pytest.raises(pvl.decoder.ParseError):
        pvl.loads('hex_number_upper = 16#100A')

    with pytest.raises(pvl.decoder.ParseError):
        pvl.loads('hex_number_upper = 16#100AZ#')
コード例 #35
0
ファイル: test_decoder.py プロジェクト: michaelaye/pvl
def test_octal():
    label = pvl.loads("""
        octal_number = 8#0107#
        positive_octal_number = +8#0107#
        negative_octal_number = -8#0107#
        End
    """)

    assert isinstance(label['octal_number'], int)
    assert label['octal_number'] == 71

    assert isinstance(label['positive_octal_number'], int)
    assert label['positive_octal_number'] == 71

    assert isinstance(label['negative_octal_number'], int)
    assert label['negative_octal_number'] == -71

    with pytest.raises(pvl.decoder.ParseError):
        pvl.loads('empty = 8##')

    with pytest.raises(pvl.decoder.ParseError):
        pvl.loads('octal_number = 8#0107')

    with pytest.raises(pvl.decoder.ParseError):
        pvl.loads('octal_number = 8#01079#')
コード例 #36
0
ファイル: test_decoder.py プロジェクト: michaelaye/pvl
def test_binary():
    label = pvl.loads("""
        binary_number = 2#0101#
        positive_binary_number = +2#0101#
        negative_binary_number = -2#0101#
        End
    """)

    assert isinstance(label['binary_number'], int)
    assert label['binary_number'] == 5

    assert isinstance(label['positive_binary_number'], int)
    assert label['positive_binary_number'] == 5

    assert isinstance(label['negative_binary_number'], int)
    assert label['negative_binary_number'] == -5

    with pytest.raises(pvl.decoder.ParseError):
        pvl.loads('empty = 2##')

    with pytest.raises(pvl.decoder.ParseError):
        pvl.loads('binary_number = 2#0101')

    with pytest.raises(pvl.decoder.ParseError):
        pvl.loads('binary_number = 2#01014201#')
コード例 #37
0
ファイル: test_decoder.py プロジェクト: cmillion/pvl
def test_binary():
    label = pvl.loads("""
        binary_number = 2#0101#
        positive_binary_number = +2#0101#
        negative_binary_number = -2#0101#
        End
    """)

    assert isinstance(label['binary_number'], int)
    assert label['binary_number'] == 5

    assert isinstance(label['positive_binary_number'], int)
    assert label['positive_binary_number'] == 5

    assert isinstance(label['negative_binary_number'], int)
    assert label['negative_binary_number'] == -5

    with pytest.raises(pvl.decoder.ParseError):
        pvl.loads('empty = 2##')

    with pytest.raises(pvl.decoder.ParseError):
        pvl.loads('binary_number = 2#0101')

    with pytest.raises(pvl.decoder.ParseError):
        pvl.loads('binary_number = 2#01014201#')
コード例 #38
0
def test_octal():
    label = pvl.loads("""
        octal_number = 8#0107#
        positive_octal_number = +8#0107#
        negative_octal_number = -8#0107#
        End
    """)

    assert isinstance(label["octal_number"], int)
    assert label["octal_number"] == 71

    assert isinstance(label["positive_octal_number"], int)
    assert label["positive_octal_number"] == 71

    assert isinstance(label["negative_octal_number"], int)
    assert label["negative_octal_number"] == -71

    with pytest.raises(LexerError):
        pvl.loads("empty = 8##")

    with pytest.raises(LexerError):
        pvl.loads("octal_number = 8#0107")

    with pytest.raises(LexerError):
        pvl.loads("octal_number = 8#01079#")
コード例 #39
0
ファイル: test_decoder.py プロジェクト: cmillion/pvl
def test_octal():
    label = pvl.loads("""
        octal_number = 8#0107#
        positive_octal_number = +8#0107#
        negative_octal_number = -8#0107#
        End
    """)

    assert isinstance(label['octal_number'], int)
    assert label['octal_number'] == 71

    assert isinstance(label['positive_octal_number'], int)
    assert label['positive_octal_number'] == 71

    assert isinstance(label['negative_octal_number'], int)
    assert label['negative_octal_number'] == -71

    with pytest.raises(pvl.decoder.ParseError):
        pvl.loads('empty = 8##')

    with pytest.raises(pvl.decoder.ParseError):
        pvl.loads('octal_number = 8#0107')

    with pytest.raises(pvl.decoder.ParseError):
        pvl.loads('octal_number = 8#01079#')
コード例 #40
0
ファイル: test_decoder.py プロジェクト: cmillion/pvl
def test_hex():
    label = pvl.loads("""
        hex_number_upper = 16#100A#
        hex_number_lower = 16#100b#
        positive_hex_number = +16#100A#
        negative_hex_number = -16#100A#
        End
    """)

    assert isinstance(label['hex_number_upper'], int)
    assert label['hex_number_upper'] == 4106

    assert isinstance(label['hex_number_lower'], int)
    assert label['hex_number_lower'] == 4107

    assert isinstance(label['positive_hex_number'], int)
    assert label['positive_hex_number'] == 4106

    assert isinstance(label['negative_hex_number'], int)
    assert label['negative_hex_number'] == -4106

    with pytest.raises(pvl.decoder.ParseError):
        pvl.loads('empty = 16##')

    with pytest.raises(pvl.decoder.ParseError):
        pvl.loads('hex_number_upper = 16#100A')

    with pytest.raises(pvl.decoder.ParseError):
        pvl.loads('hex_number_upper = 16#100AZ#')
コード例 #41
0
def test_hex():
    label = pvl.loads("""
        hex_number_upper = 16#100A#
        hex_number_lower = 16#100b#
        positive_hex_number = +16#100A#
        negative_hex_number = -16#100A#
        End
    """)

    assert isinstance(label["hex_number_upper"], int)
    assert label["hex_number_upper"] == 4106

    assert isinstance(label["hex_number_lower"], int)
    assert label["hex_number_lower"] == 4107

    assert isinstance(label["positive_hex_number"], int)
    assert label["positive_hex_number"] == 4106

    assert isinstance(label["negative_hex_number"], int)
    assert label["negative_hex_number"] == -4106

    with pytest.raises(LexerError):
        pvl.loads("empty = 16##")

    with pytest.raises(LexerError):
        pvl.loads("hex_number_upper = 16#100A")

    with pytest.raises(LexerError):
        pvl.loads("hex_number_upper = 16#100AZ#")
コード例 #42
0
def test_binary():
    label = pvl.loads("""
        binary_number = 2#0101#
        positive_binary_number = +2#0101#
        negative_binary_number = -2#0101#
        End
    """)

    assert isinstance(label["binary_number"], int)
    assert label["binary_number"] == 5

    assert isinstance(label["positive_binary_number"], int)
    assert label["positive_binary_number"] == 5

    assert isinstance(label["negative_binary_number"], int)
    assert label["negative_binary_number"] == -5

    with pytest.raises(LexerError):
        pvl.loads("empty = 2##")

    with pytest.raises(LexerError):
        pvl.loads("binary_number = 2#0101")

    with pytest.raises(LexerError):
        pvl.loads("binary_number = 2#01014201#")
コード例 #43
0
ファイル: test_encoder.py プロジェクト: planetarypy/pvl
def test_quoated_strings():
    module = pvl.PVLModule([
        ('int_like', "123"),
        ('float_like', '.2'),
        ('date', '1987-02-25'),
        ('time', '03:04:05'),
        ('datetime', '1987-02-25T03:04:05'),
        ('keyword', 'END'),
        ('restricted_chars', '&<>\'{},[]=!#()%";|'),
        ('restricted_seq', '/**/'),
    ])
    assert module == pvl.loads(pvl.dumps(module))

    encoder = pvl.encoder.IsisCubeLabelEncoder
    assert module == pvl.loads(pvl.dumps(module, cls=encoder))

    encoder = pvl.encoder.PDSLabelEncoder
    assert module == pvl.loads(pvl.dumps(module, cls=encoder))
コード例 #44
0
def test_quoated_strings():
    module = pvl.PVLModule([
        ('int_like', "123"),
        ('float_like', '.2'),
        ('date', '1987-02-25'),
        ('time', '03:04:05'),
        ('datetime', '1987-02-25T03:04:05'),
        ('keyword', 'END'),
        ('restricted_chars', '&<>\'{},[]=!#()%";|'),
        ('restricted_seq', '/**/'),
    ])
    assert module == pvl.loads(pvl.dumps(module))

    encoder = pvl.encoder.IsisCubeLabelEncoder
    assert module == pvl.loads(pvl.dumps(module, cls=encoder))

    encoder = pvl.encoder.PDSLabelEncoder
    assert module == pvl.loads(pvl.dumps(module, cls=encoder))
コード例 #45
0
ファイル: test_decoder.py プロジェクト: michaelaye/pvl
def test_quotes():
    label = pvl.loads("""
        foo = 'bar'
        empty = ''
        space = '  test  '
        double = "double'quotes"
        single = 'single"quotes'
        mixed = 'mixed"\\'quotes'
        number = '123'
        date = '1918-05-11'
        multiline = 'this is a
                     multi-line string'
        continuation = "The planet Jupi-
                        ter is very big"
        formating = "\\n\\t\\f\\v\\\\\\n\\t\\f\\v\\\\"
        End
    """)

    assert isinstance(label['foo'], six.text_type)
    assert label['foo'] == 'bar'

    assert isinstance(label['empty'], six.text_type)
    assert label['empty'] == ''

    assert isinstance(label['space'], six.text_type)
    assert label['space'] == 'test'

    assert isinstance(label['double'], six.text_type)
    assert label['double'] == "double'quotes"

    assert isinstance(label['single'], six.text_type)
    assert label['single'] == 'single"quotes'

    assert isinstance(label['single'], six.text_type)
    assert label['mixed'] == 'mixed"\'quotes'

    assert isinstance(label['number'], six.text_type)
    assert label['number'] == '123'

    assert isinstance(label['date'], six.text_type)
    assert label['date'] == '1918-05-11'

    assert isinstance(label['multiline'], six.text_type)
    assert label['multiline'] == 'this is a multi-line string'

    assert isinstance(label['continuation'], six.text_type)
    assert label['continuation'] == 'The planet Jupiter is very big'

    assert isinstance(label['formating'], six.text_type)
    assert label['formating'] == '\n\t\f\v\\\n\t\f\v\\'

    with pytest.raises(pvl.decoder.ParseError):
        pvl.loads('foo = "bar')

    with pytest.raises(pvl.decoder.ParseError):
        pvl.loads("foo = 'bar")

    with pytest.raises(pvl.decoder.ParseError):
        pvl.loads("foo = '\\bar'")
コード例 #46
0
ファイル: test_decoder.py プロジェクト: jlaura/pvl
def test_octal():
    label = pvl.loads("""
        octal_number = 8#0107#
        positive_octal_number = +8#0107#
        negative_octal_number = -8#0107#
        End
    """)

    assert isinstance(label['octal_number'], int)
    assert label['octal_number'] == 71

    assert isinstance(label['positive_octal_number'], int)
    assert label['positive_octal_number'] == 71

    assert isinstance(label['negative_octal_number'], int)
    assert label['negative_octal_number'] == -71
コード例 #47
0
ファイル: test_decoder.py プロジェクト: jlaura/pvl
def test_binary():
    label = pvl.loads("""
        binary_number = 2#0101#
        positive_binary_number = +2#0101#
        negative_binary_number = -2#0101#
        End
    """)

    assert isinstance(label['binary_number'], int)
    assert label['binary_number'] == 5

    assert isinstance(label['positive_binary_number'], int)
    assert label['positive_binary_number'] == 5

    assert isinstance(label['negative_binary_number'], int)
    assert label['negative_binary_number'] == -5
コード例 #48
0
ファイル: test_decoder.py プロジェクト: michaelaye/pvl
def test_spacing():
    label = pvl.loads("""
        foo = bar
        nospace=good
          lots_of_spacing    =    alsogood
        same = line no = problem; like=aboss
        End
    """)

    assert isinstance(label, Label)
    assert label['foo'] == 'bar'
    assert label['nospace'] == 'good'
    assert label['lots_of_spacing'] == 'alsogood'
    assert label['same'] == 'line'
    assert label['no'] == 'problem'
    assert label['like'] == 'aboss'
コード例 #49
0
ファイル: io_pvl.py プロジェクト: USGS-Astrogeology/plio
def extract_keywords(header, *args):
    """
    For a given header, find all of the keys and return an unnested dict.
    """
    try:
        header = pvl.load(header)
    except:
        header = pvl.loads(header)

    res = {}
    # Iterate through all of the requested keys
    for a in args:
        try:
            res[a] = find_in_dict(a)
        except:
            res[a] = None
    return res
コード例 #50
0
ファイル: test_decoder.py プロジェクト: michaelaye/pvl
def test_set():
    label = pvl.loads("""
        strings = {a, b, c}
        nospace={a,b,c}
        numbers = {1, 2, 3}
        mixed = {a, 1, 2.5}
        multiline = {a,
                     b,
                     c}
        empty = {}
        End
    """)

    assert isinstance(label['strings'], set)
    assert len(label['strings']) == 3
    assert 'a' in label['strings']
    assert 'b' in label['strings']
    assert 'c' in label['strings']

    assert isinstance(label['nospace'], set)
    assert len(label['nospace']) == 3
    assert 'a' in label['nospace']
    assert 'b' in label['nospace']
    assert 'c' in label['nospace']

    assert isinstance(label['numbers'], set)
    assert len(label['numbers']) == 3
    assert 1 in label['numbers']
    assert 2 in label['numbers']
    assert 3 in label['numbers']

    assert isinstance(label['mixed'], set)
    assert len(label['mixed']) == 3
    assert 'a' in label['mixed']
    assert 1 in label['mixed']
    assert 2.5 in label['mixed']

    assert isinstance(label['multiline'], set)
    assert len(label['multiline']) == 3
    assert 'a' in label['multiline']
    assert 'b' in label['multiline']
    assert 'c' in label['multiline']

    assert isinstance(label['empty'], set)
    assert len(label['empty']) == 0
コード例 #51
0
ファイル: test_decoder.py プロジェクト: michaelaye/pvl
def test_sequence():
    label = pvl.loads("""
        strings = (a, b, c)
        nospace=(a,b,c)
        numbers = (1, 2, 3)
        mixed = (a, 1, 2.5)
        empty = ()
        multiline = (a,
                     b,
                     c)
        End
    """)

    assert isinstance(label['strings'], list)
    assert len(label['strings']) == 3
    assert label['strings'][0] == 'a'
    assert label['strings'][1] == 'b'
    assert label['strings'][2] == 'c'

    assert isinstance(label['nospace'], list)
    assert len(label['nospace']) == 3
    assert label['nospace'][0] == 'a'
    assert label['nospace'][1] == 'b'
    assert label['nospace'][2] == 'c'

    assert isinstance(label['numbers'], list)
    assert len(label['numbers']) == 3
    assert label['numbers'][0] == 1
    assert label['numbers'][1] == 2
    assert label['numbers'][2] == 3

    assert isinstance(label['mixed'], list)
    assert len(label['mixed']) == 3
    assert label['mixed'][0] == 'a'
    assert label['mixed'][1] == 1
    assert label['mixed'][2] == 2.5

    assert isinstance(label['empty'], list)
    assert len(label['empty']) == 0

    assert isinstance(label['multiline'], list)
    assert len(label['multiline']) == 3
    assert label['multiline'][0] == 'a'
    assert label['multiline'][1] == 'b'
    assert label['multiline'][2] == 'c'
コード例 #52
0
ファイル: test_decoder.py プロジェクト: michaelaye/pvl
def test_alt_group_style():
    label = pvl.loads("""
        OBJECT               = TEST1
          FOO                = BAR
        END_OBJECT           = TEST1

        GROUP                = TEST2
          FOO                = BAR
        END_GROUP            = TEST2

        END
    """)
    test_group = label['TEST1']
    assert isinstance(test_group, LabelObject)
    assert test_group['FOO'] == 'BAR'

    embedded_object = label['TEST2']
    assert isinstance(embedded_object, LabelGroup)
    assert embedded_object['FOO'] == 'BAR'
コード例 #53
0
ファイル: test_decoder.py プロジェクト: michaelaye/pvl
def test_integers():
    label = pvl.loads("""
        integer = 42
        positive_integer = +123
        negitive_integer = -1
        invalid_integer = 1a2
        End
    """)

    assert isinstance(label['integer'], int)
    assert label['integer'] == 42

    assert isinstance(label['integer'], int)
    assert label['positive_integer'] == 123

    assert isinstance(label['negitive_integer'], int)
    assert label['negitive_integer'] == -1

    assert isinstance(label['invalid_integer'], six.text_type)
    assert label['invalid_integer'] == '1a2'
コード例 #54
0
ファイル: test_decoder.py プロジェクト: jlaura/pvl
def test_hex():
    label = pvl.loads("""
        hex_number_upper = 16#100A#
        hex_number_lower = 16#100b#
        positive_hex_number = +16#100A#
        negative_hex_number = -16#100A#
        End
    """)

    assert isinstance(label['hex_number_upper'], int)
    assert label['hex_number_upper'] == 4106

    assert isinstance(label['hex_number_lower'], int)
    assert label['hex_number_lower'] == 4107

    assert isinstance(label['positive_hex_number'], int)
    assert label['positive_hex_number'] == 4106

    assert isinstance(label['negative_hex_number'], int)
    assert label['negative_hex_number'] == -4106
コード例 #55
0
ファイル: test_decoder.py プロジェクト: michaelaye/pvl
def test_delimiters():
    label = pvl.loads("""
        foo = 1;
        Object = embedded_object;
          foo = bar;
        End_Object;
        bar = 2;
        Group = embedded_group;
          foo = bar;
        End_Group;
        End;
    """)

    assert isinstance(label, Label)
    assert label['foo'] == 1
    assert label['bar'] == 2

    assert isinstance(label['embedded_object'], LabelObject)
    assert label['embedded_object']['foo'] == 'bar'

    assert isinstance(label['embedded_group'], LabelGroup)
    assert label['embedded_group']['foo'] == 'bar'
コード例 #56
0
ファイル: test_decoder.py プロジェクト: michaelaye/pvl
def test_special():
    label = pvl.loads("""
        none1 = NULL
        none2 = Null
        true1 = TRUE
        true2 = True
        true3 = true
        false1 = FALSE
        false2 = False
        false3 = false
        End
    """)

    assert label['none1'] is None
    assert label['none2'] is None

    assert label['true1'] is True
    assert label['true2'] is True
    assert label['true3'] is True

    assert label['false1'] is False
    assert label['false2'] is False
    assert label['false3'] is False
コード例 #57
0
ファイル: test_decoder.py プロジェクト: jlaura/pvl
def test_units():
    label = pvl.loads("""
        foo = 42 <beards>
        g = 9.8 <m/s>
        list = (1, 2, 3) <numbers>
        cool = (1 <number>)
        End
    """)
    assert isinstance(label['foo'], Units)
    assert label['foo'].value == 42
    assert label['foo'].units == 'beards'

    assert isinstance(label['g'], Units)
    assert label['g'].value == 9.8
    assert label['g'].units == 'm/s'

    assert isinstance(label['list'], Units)
    assert isinstance(label['list'].value, list)
    assert label['list'].units == 'numbers'

    assert isinstance(label['cool'], list)
    assert isinstance(label['cool'][0], Units)
    assert label['cool'][0].value == 1
    assert label['cool'][0].units == 'number'
コード例 #58
0
ファイル: test_decoder.py プロジェクト: michaelaye/pvl
def test_exponents():
    label = pvl.loads("""
        capital = -1.E-3
        lower = -1.e-3
        small = -0.45e6
        int = 31459e1
        invalid = 1e
        End
    """)

    assert isinstance(label['capital'], float)
    assert label['capital'] == -1.0E-3

    assert isinstance(label['lower'], float)
    assert label['lower'] == -1.0E-3

    assert isinstance(label['small'], float)
    assert label['small'] == -0.45E6

    assert isinstance(label['int'], float)
    assert label['int'] == 31459e1

    assert isinstance(label['invalid'], six.text_type)
    assert label['invalid'] == '1e'
コード例 #59
0
ファイル: test_encoder.py プロジェクト: planetarypy/pvl
def test_pds_encoder():
    for filename in PDS_LABELS:
        label = pvl.load(filename)
        encoder = pvl.encoder.PDSLabelEncoder
        assert label == pvl.loads(pvl.dumps(label, cls=encoder))
コード例 #60
0
ファイル: test_encoder.py プロジェクト: planetarypy/pvl
def test_default_encoder():
    for filename in PDS_LABELS:
        label = pvl.load(filename)
        assert label == pvl.loads(pvl.dumps(label))