mivot_validator.utils package

Submodules

mivot_validator.utils.dict_utils module

Code imported from SVOM Created on 29 mai 2019

@author: michel

class mivot_validator.utils.dict_utils.DictUtils[source]

Bases: object

static class processing implementing convenient operation on dictionaries

static find_item_by_key(dictionnary, key)[source]

Look for the first dictionary item attached to key

Parameters:
  • dictionary ({}) – dictionary to be explored

  • key (string) – searched key

static get_fatal_value(dictionary, key)[source]

returns dictionary[key] if available and trigger a system exit otherwise.

Parameters:
  • dictionary (Python Dict) – dictionary

  • key (string) – key of the searched value

Returns:

the value attached to the key

Return type:

any supported Dict value

static get_optional_value(dictionary, key, null=None)[source]

returns dictionary[key] if available or a null value otherwise.

Parameters:
  • dictionary (Python Dict) – dictionary

  • key (string) – key of the searched value

  • null (string) – value taken when the key os not available (None by default)

Returns:

the value attached to the key or the null value

Return type:

any supported Dict value

static get_permanent_object(dico)[source]

This method make the object content independent of a specific run context It us used to format object in a way they can be checked in unit demo dates values are replaced with DATE and the seq_id with SEQID.

Parameters:

dico (anything) – object to be formated

static get_permanent_string(text)[source]

This method make the string independent of a specific run context It us used to format object in a way they can be checked in unit demo dates values are replaced with DATE and the seq_id with SEQID.

Parameters:

text (string) – string to be formated

static get_prefixed_keys_dict(dictionnary, prefix)[source]

Returns a copy of dict with all keys prefixed with prefix Works only art root level, no recursion.

Parameters:
  • dictionnary (dict) – dict on which key prefixes must be applied

  • prefix (string) – prefix to be aplied to the keys

Return type:

prefixed dict

static get_pretty_json(dictionnary)[source]
Returns:

A pretty string representation of the dictionary

Return type:

Python Dict

static get_required_value(dictionary, key)[source]

returns dictionary[key] if available and rises an exception otherwise.

Parameters:
  • dictionary (Python Dict) – dictionary

  • key (string) – key of the searched value

Returns:

the value attached to the key

Return type:

any supported Dict value

static print_pretty_json(dictionnary)[source]
Returns:

Print out pretty string representation of the dictionary

static read_dict_from_file(filename, fatal=False)[source]

Read a Dict in filename, rises an exception if something goes wrong.

Parameters:
  • filename (string) – filename

  • fatal (boolean) – trigger a systeml exit if true

Returns:

the Dict extracted from the file

Return type:

Python Dict

static read_dict_from_url(url, fatal=False)[source]

Read a Dict from url, rises an exception if something goes wrong.

Parameters:
  • url (string) – url

  • fatal (boolean) – trigger a systeml exit if true

Returns:

the Dict extracted from the file

Return type:

Python Dict

static remove_comment(dictionary)[source]

Remove all comment keys (“$desc”). not recursive.

Parameters:

dictionary (Python Dict) – dictionary

static write_dict_from_file(dictionary, filename, fatal=False)[source]

Write the dictionary in filename, rises an exception if something goes wrong.

Parameters:
  • filename (string) – filename

  • fatal (boolean) – trigger a systeml exit if true

mivot_validator.utils.json_encoder module

Created on 1 avr. 2020

@author: laurentmichel

class mivot_validator.utils.json_encoder.MyEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]

Bases: JSONEncoder

classdocs

default(o)[source]

Implement this method in a subclass such that it returns a serializable object for o, or calls the base implementation (to raise a TypeError).

For example, to support arbitrary iterators, you could implement default like this:

def default(self, o):
    try:
        iterable = iter(o)
    except TypeError:
        pass
    else:
        return list(iterable)
    # Let the base class default method raise the TypeError
    return super().default(o)

mivot_validator.utils.json_tools module

Created on Jan 11, 2021

@author: laurentmichel

class mivot_validator.utils.json_tools.JsonTools[source]

Bases: object

classdocs

static is_join(input_list)[source]

Check if input_list contains a join key

static remove_dict_key(dictionary, key)[source]
{key: {“A”: “a”, “B”: “b”}}

–> {“A”: “a”, “B”: “b”}

{key: [{“A1”: “a”, “B1”: “b”}, {“A2”: “a”, “B2”: “b”}]}

–> [{“A1”: “a”, “B1”: “b”}, {“A2”: “a”, “B2”: “b”}]

static remove_key(dictionary, key)[source]

remove a key from a dictionary

static remove_list_key(dictionary, key)[source]
[{key: {“A1”: “a”, “B1”: “b”}}]

–> [{“A1”: “a”, “B1”: “b”}]

[{key: [{“A1”: “a”, “B1”: “b”}, {“A2”: “a”, “B2”: “b”}]}]

–> [{“A1”: “a”, “B1”: “b”}, {“A2”: “a”, “B2”: “b”}]

mivot_validator.utils.logger_setup module

Global logger setup Must be used by the whole application

The default format can be restored at any time with LoggerSetup.set_default_format() The log level can be set at any time with LoggerSetup.set_debug/info/warning/error_level The level is set at INFO by default

Created on 4 December 2019

@author: michel

class mivot_validator.utils.logger_setup.LoggerSetup[source]

Bases: object

manage the logger setup

static get_logger()[source]

Format and return the system logger :return : system logger :rtype: logger

static restore_default_level()[source]

restore the message level with the last value set by a setter INFO by default

static set_debug_level()[source]

Switch to debug level

static set_default_format()[source]

set the default message format

static set_error_level()[source]

Switch to error level

static set_info_level()[source]

Switch to info level

static set_warning_level()[source]

Switch to warning level

mivot_validator.utils.quantity_converter module

Created on 25 Jan 2022

@author: laurentmichel

class mivot_validator.utils.quantity_converter.QuantityConverter(params)[source]

Bases: object

classdocs

static parallax_to_distance(parallax)[source]

Parallax given in mas distance returned in parsec

mivot_validator.utils.xml_utils module

Created on 16 Dec 2021

@author: laurentmichel

class mivot_validator.utils.xml_utils.XmlUtils[source]

Bases: object

classdocs

static assertXmltreeEquals(xmltree1, xmltree2, message)[source]

Compare two xml trees

static assertXmltreeEqualsFile(xmltree1, xmltree2_file, message='')[source]

Compare a xml tree with a file

static get_attribute_by_role(model_view, dmrole)[source]

get an attribute by its dmrole

static get_attribute_value_by_role(model_view, dmrole)[source]

get an attribute value by its dmrole

static get_instance_by_role(model_view, dmrole)[source]

get an instance by its dmrole

static get_instance_by_type(model_view, dmtype)[source]

get an instance by its dmtype

static pretty_print(xmltree)[source]

pretty print an xml tree

static pretty_string(xmltree)[source]

pretty print a xml tree and return it as a string

static set_column_indices(mapping_block, index_map)[source]

add column ranks to attribute having a ref. Using ranks allow to identify columns even numpy raw have been serialised as []

static set_column_units(mapping_block, unit_map)[source]

add field unit to attribute having a ref. Used for performing unit conversions

static xmltree_from_file(file_path)[source]

return an xml tree from a file

static xmltree_to_file(xmltree, file_path)[source]

write a xml tree to a file

Module contents

This package contains utility functions and classes used by the validator.