From b51d7fb85e1475e9ea9165474fcb062d8e6c7737 Mon Sep 17 00:00:00 2001 From: Helveg Date: Thu, 28 Mar 2024 16:04:27 +0100 Subject: [PATCH] =?UTF-8?q?Bump=20version:=200.0.0-b6=20=E2=86=92=200.0.0-?= =?UTF-8?q?b7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bsb_json/__init__.py | 2 +- bsb_json/parser.py | 7 +------ pyproject.toml | 2 +- tests/test_configuration.py | 13 ++++++------- tests/test_parser.py | 34 +++++++++++++++++----------------- 5 files changed, 26 insertions(+), 32 deletions(-) diff --git a/bsb_json/__init__.py b/bsb_json/__init__.py index 946d574..865e90c 100644 --- a/bsb_json/__init__.py +++ b/bsb_json/__init__.py @@ -4,4 +4,4 @@ from .schema import get_json_schema, get_schema -__version__ = "0.0.0-b6" +__version__ = "0.0.0-b7" diff --git a/bsb_json/parser.py b/bsb_json/parser.py index 3025517..bca6236 100644 --- a/bsb_json/parser.py +++ b/bsb_json/parser.py @@ -7,12 +7,7 @@ import os import numpy as np -from bsb import ( - ConfigurationParser, - ConfigurationWarning, - ParserError, - warn, -) +from bsb import ConfigurationParser, ConfigurationWarning, ParserError, warn class JsonImportError(ParserError): diff --git a/pyproject.toml b/pyproject.toml index 8eab388..eb75375 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,7 +34,7 @@ dev = [ profile = "black" [tool.bumpversion] -current_version = "0.0.0-b6" +current_version = "0.0.0-b7" parse = """(?x) (?P0|[1-9]\\d*)\\. (?P0|[1-9]\\d*)\\. diff --git a/tests/test_configuration.py b/tests/test_configuration.py index cb9104b..4bbc7ea 100644 --- a/tests/test_configuration.py +++ b/tests/test_configuration.py @@ -2,10 +2,9 @@ import unittest from tempfile import TemporaryFile -from bsb import config -from bsb.config import Configuration, from_json -from bsb.core import Scaffold -from bsb_test import RandomStorageFixture, get_test_config, get_test_config_tree +from bsb import Configuration, Scaffold, config, parse_configuration_file, \ + parse_configuration_content +from bsb_test import RandomStorageFixture, get_test_config_tree def as_json(name: str): @@ -25,18 +24,18 @@ def test_json_minimal_bootstrap(self): with TemporaryFile(mode="w+") as f: f.write(as_json("minimal")) f.seek(0) - config = from_json(f) + config = parse_configuration_file(f, parser="json") Scaffold(config, self.storage) def test_json_minimal_content_bootstrap(self): - config = from_json(data=as_json("minimal")) + config = parse_configuration_content(as_json("minimal"), parser="json") Scaffold(config, self.storage) def test_json_full_bootstrap(self): with TemporaryFile(mode="w+") as f: f.write(as_json("full_compile")) f.seek(0) - config = from_json(f) + config = parse_configuration_file(f, parser="json") Scaffold(config, self.storage) @unittest.expectedFailure diff --git a/tests/test_parser.py b/tests/test_parser.py index 1105b16..7c04477 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -1,9 +1,9 @@ import pathlib import unittest -from bsb import config -from bsb.exceptions import * -from bsb_test import get_data_path +from bsb import ConfigurationWarning, PluginError, get_configuration_parser + +from bsb_json.parser import JsonReferenceError def get_content(file: str): @@ -12,15 +12,15 @@ def get_content(file: str): class TestJsonBasics(unittest.TestCase): def test_get_parser(self): - config.get_parser("json") - self.assertRaises(PluginError, config.get_parser, "doesntexist") + get_configuration_parser("json") + self.assertRaises(PluginError, get_configuration_parser, "doesntexist") def test_parse_empty_doc(self): - tree, meta = config.get_parser("json").parse(get_content("doc.json")) + tree, meta = get_configuration_parser("json").parse(get_content("doc.json")) self.assertEqual({}, tree, "'doc.json' parse should produce empty dict") def test_parse_basics(self): - tree, meta = config.get_parser("json").parse(get_content("basics.json")) + tree, meta = get_configuration_parser("json").parse(get_content("basics.json")) self.assertEqual(3, tree["list"][2], "Incorrectly parsed basic JSON") self.assertEqual( "just like that", @@ -34,7 +34,7 @@ def test_parse_basics(self): class TestJsonRef(unittest.TestCase): def test_indoc_reference(self): - tree, meta = config.get_parser("json").parse(get_content("intradoc_refs.json")) + tree, meta = get_configuration_parser("json").parse(get_content("intradoc_refs.json")) self.assertNotIn("$ref", tree["refs"]["whats the"], "Ref key not removed") self.assertEqual("key", tree["refs"]["whats the"]["secret"]) self.assertEqual("is hard", tree["refs"]["whats the"]["nested secrets"]["vim"]) @@ -43,12 +43,12 @@ def test_indoc_reference(self): ) self.assertEqual(tree["refs"]["whats the"], tree["refs"]["omitted_doc"]) with self.assertRaises(JsonReferenceError, msg="Should raise 'ref not a dict'"): - tree, meta = config.get_parser("json").parse( + tree, meta = get_configuration_parser("json").parse( get_content("intradoc_nodict_ref.json") ) def test_far_references(self): - tree, meta = config.get_parser("json").parse( + tree, meta = get_configuration_parser("json").parse( get_content("interdoc_refs.json"), path=str( (pathlib.Path(__file__).parent / "parser_tests" / "interdoc_refs.json") @@ -60,7 +60,7 @@ def test_far_references(self): self.assertEqual("just like that", tree["refs"]["whats the"]["oh yea"]) def test_double_ref(self): - tree, meta = config.get_parser("json").parse( + tree, meta = get_configuration_parser("json").parse( get_content("doubleref.json"), path=str( (pathlib.Path(__file__).parent / "parser_tests" / "doubleref.json") @@ -68,7 +68,7 @@ def test_double_ref(self): ) def test_ref_str(self): - parser = config.get_parser("json") + parser = get_configuration_parser("json") tree, meta = parser.parse( get_content("doubleref.json"), path=str( @@ -85,14 +85,14 @@ def test_ref_str(self): class TestJsonImport(unittest.TestCase): def test_indoc_import(self): - tree, meta = config.get_parser("json").parse(get_content("indoc_import.json")) + tree, meta = get_configuration_parser("json").parse(get_content("indoc_import.json")) self.assertEqual(["with", "importable"], list(tree["imp"].keys())) self.assertEqual("are", tree["imp"]["importable"]["dicts"]["that"]) def test_indoc_import_list(self): from bsb_json.parser import parsed_list - tree, meta = config.get_parser("json").parse( + tree, meta = get_configuration_parser("json").parse( get_content("indoc_import_list.json") ) self.assertEqual(["with", "importable"], list(tree["imp"].keys())) @@ -100,14 +100,14 @@ def test_indoc_import_list(self): self.assertEqual(parsed_list, type(tree["imp"]["with"][2]), "message") def test_indoc_import_value(self): - tree, meta = config.get_parser("json").parse( + tree, meta = get_configuration_parser("json").parse( get_content("indoc_import_other.json") ) self.assertEqual(["with", "importable"], list(tree["imp"].keys())) self.assertEqual("a", tree["imp"]["with"]) def test_import_merge(self): - tree, meta = config.get_parser("json").parse( + tree, meta = get_configuration_parser("json").parse( get_content("indoc_import_merge.json") ) self.assertEqual(2, len(tree["imp"].keys())) @@ -124,7 +124,7 @@ def test_import_merge(self): def test_import_overwrite(self): with self.assertWarns(ConfigurationWarning) as warning: - tree, meta = config.get_parser("json").parse( + tree, meta = get_configuration_parser("json").parse( get_content("indoc_import_overwrite.json") ) self.assertEqual(2, len(tree["imp"].keys()))