コード例 #1
0
def test_roundtrip_no_rs():
    """Compact sequences without RS round-trip correctly"""
    encoder = JSONSeqEncoder(with_rs=False)
    results = list(encoder.encode(range(100)))
    decoder = JSONSeqDecoder()
    results = list(decoder.decode(results))
    assert results == list(range(100))
コード例 #2
0
def test_roundtrip_default_rs_pretty_printed():
    """Sequences with RS round-trip correctly"""
    encoder = JSONSeqEncoder(indent=2)
    results = list(
        encoder.iterencode(({
            "a": i,
            "b": 2,
            "c": None
        } for i in range(10))))
    decoder = JSONSeqDecoder()
    results = list(decoder.decode(results))
    assert results == list({"a": i, "b": 2, "c": None} for i in range(10))
コード例 #3
0
ファイル: maintenance.py プロジェクト: ACM-CBU/TestBot1
    async def viewLogs(self, ctx: commands.Context, *args: str):
        if not args:
            return await ctx.send_help()

        kwargs = [
            "journalctl", *args, "-u", "red@TheHatBot", "-o", "json",
            "--no-pager"
        ]

        json_file_path = Path(__file__).absolute(
        ).parent.parent.parent.parent.parent.joinpath("test.json").absolute()

        json_file = open(json_file_path, 'w')
        subprocess.call(kwargs, stdout=json_file)

        json_file.close()
        result_string = ''

        with open(json_file_path.absolute()) as f:
            # "MESSAGE" : "Started TheHatBot redbot.",
            # "__REALTIME_TIMESTAMP" : "1595382054920981",
            for obj in JSONSeqDecoder().decode(f):
                num = int(obj.get("__REALTIME_TIMESTAMP")) // 1000000
                time_stamp = datetime.fromtimestamp(num).strftime(
                    "%Y-%m-%d %I:%M:%S")
                result_string += f'{time_stamp} -- {obj.get("MESSAGE")}\n'
        if not result_string:
            result_string = "There was no logs for specified time"

        for partial_result in chat_formatting.pagify(result_string,
                                                     shorten_by=20):
            await ctx.send(chat_formatting.box(partial_result, lang='python'))
コード例 #4
0
ファイル: cli.py プロジェクト: lluft/tilesets-cli
def validate_source(source_path):
    """Validate your source file.
    $ tilesets validate-source <path/to/your/src/file>
    """
    line_count = 1
    with open(source_path, 'r') as inf:
        click.echo("Validating {0} ...".format(source_path))
        feature = None
        try:
            for feature in JSONSeqDecoder().decode(inf):
                utils.validate_geojson(feature)
                line_count += 1
        except JSONDecodeError:
            click.echo(
                "Error: Invalid JSON on line {} \n Invalid Content: {} \n".
                format(line_count, feature))
            sys.exit(1)
        except jsonschema.exceptions.ValidationError:
            click.echo(
                "Error: Invalid geojson found on line {} \n Invalid Feature: {} \n Note - Geojson must be line delimited."
                .format(line_count, feature))
            sys.exit(1)

    click.echo('✔ valid')
コード例 #5
0
def test_decode_empty():
    """Decoding an empty sequence produces an empty sequence"""
    decoder = JSONSeqDecoder()
    assert list(decoder.decode([])) == []
コード例 #6
0
def test_fio_output_terse(coutwildrnp_geojsons_path):
    """Test terse usage with pretty-printed geojsons"""
    results = list(JSONSeqDecoder().decode(open(coutwildrnp_geojsons_path)))
    assert len(results) == 67
コード例 #7
0
def test_fio_output(coutwildrnp_geojsons_path):
    """Test with real world pretty-printed geojsons"""
    decoder = JSONSeqDecoder()
    with open(coutwildrnp_geojsons_path) as f:
        results = list(decoder.decode(f))
    assert len(results) == 67