class BoxTest(unittest.TestCase): def setUp(self): self.box = Box(PackSize.A) def testEmptyByDefault(self): # then self.assertTrue(self.box.isEmpty()) def testOccupied(self): # given pack = Pack("1", PackSize.A) self.box.put(pack) # then self.assertFalse(self.box.isEmpty())
def _to_yaml(data): try: return Box.from_yaml(data) except YAMLError: raise BoxError('File is not YAML as expected') except BoxError: return BoxList.from_yaml(data)
def _to_json(data): try: return Box.from_json(data) except JSONDecodeError: raise BoxError('File is not JSON as expected') except BoxError: return BoxList.from_json(data)
def store_cfg(filename: Union[str, Path], d: dict): filename = str(filename) data = Box(d) if "yml" in filename or "yaml" in filename: Box(XConfig.decode(data.to_dict())).to_yaml(filename) if "json" in filename: Box(XConfig.decode(data.to_dict())).to_json(filename) if "toml" in filename: Box(XConfig.decode(data.to_dict())).to_toml(filename)
def _to_msgpack(file, _, __, **kwargs): if not msgpack_available: raise BoxError( f'File "{file}" is msgpack but no package is available to open it. Please install "msgpack"' ) try: return Box.from_msgpack(filename=file, **kwargs) except (UnpackException, ValueError): raise BoxError("File is not msgpack as expected") except BoxError: return BoxList.from_msgpack(filename=file, **kwargs)
def _to_toml(file, encoding, errors, **kwargs): if not toml_available: raise BoxError( f'File "{file}" is toml but no package is available to open it. Please install "toml"' ) try: return Box.from_toml(filename=file, encoding=encoding, errors=errors, **kwargs) except TomlDecodeError: raise BoxError("File is not TOML as expected")
def _to_json(file, encoding, errors, **kwargs): try: return Box.from_json(filename=file, encoding=encoding, errors=errors, **kwargs) except JSONDecodeError: raise BoxError("File is not JSON as expected") except BoxError: return BoxList.from_json(filename=file, encoding=encoding, errors=errors, **kwargs)
def _to_yaml(file, encoding, errors, **kwargs): if not yaml_available: raise BoxError( f'File "{file}" is yaml but no package is available to open it. Please install "ruamel.yaml" or "PyYAML"' ) try: return Box.from_yaml(filename=file, encoding=encoding, errors=errors, **kwargs) except YAMLError: raise BoxError("File is not YAML as expected") except BoxError: return BoxList.from_yaml(filename=file, encoding=encoding, errors=errors, **kwargs)
def add_routes(config): """ Called once per thread start, in order to call :func:`solute.epfl.core.epflcomponentbase.ComponentBase.add_pyramid_routes` for every component provided by epfl through this package. """ Box.add_pyramid_routes(config) LoginBox.add_pyramid_routes(config) ModalBox.add_pyramid_routes(config) TabsLayout.add_pyramid_routes(config) NavLayout.add_pyramid_routes(config) ColLayout.add_pyramid_routes(config) CardinalLayout.add_pyramid_routes(config) Link.add_pyramid_routes(config) RecursiveTree.add_pyramid_routes(config) ListLayout.add_pyramid_routes(config) PrettyListLayout.add_pyramid_routes(config) PaginatedListLayout.add_pyramid_routes(config) LinkListLayout.add_pyramid_routes(config) GroupedLinkListLayout.add_pyramid_routes(config) HoverLinkListLayout.add_pyramid_routes(config) ContextListLayout.add_pyramid_routes(config) TableLayout.add_pyramid_routes(config) SelectableList.add_pyramid_routes(config) TypeAhead.add_pyramid_routes(config) Form.add_pyramid_routes(config) Button.add_pyramid_routes(config) TextInput.add_pyramid_routes(config) TextEditor.add_pyramid_routes(config) CodeEditor.add_pyramid_routes(config) NumberInput.add_pyramid_routes(config) Textarea.add_pyramid_routes(config) Radio.add_pyramid_routes(config) ButtonRadio.add_pyramid_routes(config) Toggle.add_pyramid_routes(config) SimpleToggle.add_pyramid_routes(config) Checkbox.add_pyramid_routes(config) Select.add_pyramid_routes(config) Upload.add_pyramid_routes(config) Download.add_pyramid_routes(config) ColorPicker.add_pyramid_routes(config) ColorThief.add_pyramid_routes(config) DatetimeInput.add_pyramid_routes(config) AutoCompleteInput.add_pyramid_routes(config) PasswordInput.add_pyramid_routes(config) Badge.add_pyramid_routes(config) Diagram.add_pyramid_routes(config) Progress.add_pyramid_routes(config) StackedProgress.add_pyramid_routes(config) Image.add_pyramid_routes(config) Text.add_pyramid_routes(config) Placeholder.add_pyramid_routes(config) PlainHtml.add_pyramid_routes(config) Breadcrumb.add_pyramid_routes(config) Carousel.add_pyramid_routes(config) Popover.add_pyramid_routes(config) TextList.add_pyramid_routes(config) Dropdown.add_pyramid_routes(config) EmbeddedVideo.add_pyramid_routes(config)
def setUp(self): self.box = Box(PackSize.A)
def _to_toml(data): try: return Box.from_toml(data) except TomlDecodeError: raise BoxError('File is not TOML as expected')
def setUp(self): self.boxGroup = BoxGroup() self.boxGroup.boxes = [Box(PackSize.A), Box(PackSize.B)]
def complex_data(): np.random.seed(666) placeholders = [] env_variables = [] pl_generator = PlaceholderGenerator() sample_dict = { "one": pl_generator.create_placeholder( placeholders, "int", [6, 7, 8, "default=10"] ), "two": np.random.randint(-50, 50, (3, 3)).tolist(), "three": { "3.1": "TrueValue", "2.1": [False, False], "name": { "name_1": pl_generator.create_placeholder(placeholders, "float"), "name_2": 2, "name_3": { "this_is_a_list": [3.3, 3.3], "this_is_A_dict": { "a": { "f": True, "s": False, "numpy_array": np.array([1.0, 2, 3]), "numpy_data": np.array([1.0, 2, 3])[0], "tuple": ("a", "b", "2"), "boxlist": BoxList([1, 2, 3, 4]), "boxdict": Box({"a": 2.2}), } }, }, }, }, "first": { "f1": pl_generator.create_placeholder( placeholders, "str", ["alpha", "beta", "gamma"] ), # placeholders[2], "f2": 2.22, "f3": [3, 3, 3, 3, 3, 3], "external": { "ext": np.random.uniform(-2, 2, (2, 3)).tolist(), "ext_name": [pl_generator.create_placeholder(placeholders, "bool")], }, "ops": { "o1": pl_generator.create_placeholder(placeholders), # placeholders[4], "o2": pl_generator.create_placeholder( placeholders, "path" ), # placeholders[5], "o3": pl_generator.create_placeholder( placeholders, "date" ), # placeholders[6], "o4": pl_generator.create_placeholder( placeholders, "str", ["A", "B", "C", "default=C"] ), # placeholders[7], "o5": pl_generator.create_placeholder(placeholders), # placeholders[8], "o6": pl_generator.create_placeholder(placeholders), # placeholders[9] }, "env": [ pl_generator.create_placeholder( env_variables, "env" ), # env_variables[0], pl_generator.create_placeholder(env_variables, "env"), ], "key": { "with": 120, "dots": pl_generator.create_placeholder(placeholders, "object"), }, "key.with.dots": pl_generator.create_placeholder( placeholders ), # placeholders[10], "key.with...many.....dots": pl_generator.create_placeholder(placeholders), "nested.key": {"with.dots": pl_generator.create_placeholder(placeholders)}, "placeholder_object": pl_generator.create_placeholder(placeholders), "placeholder_cfg": pl_generator.create_placeholder( placeholders, "cfg" ), # placeholders[15], "placeholder_cfg_root": pl_generator.create_placeholder( placeholders, "cfg_root" ), # , }, } schema = Schema( { "one": Or(int, str), "two": list, "three": { "3.1": str, "2.1": [bool], "name": dict, }, "first": {Regex(""): Or(str, int, list, float, dict)}, } ) to_be_raplaced_keys = sorted( [ "three.name", "three.name.name_3", "three.name.name_3.this_is_A_dict", "first", "first.external", ], reverse=True, ) return { "data": XConfig.decode(sample_dict), "schema": schema, "placeholders": placeholders, "environment_variables": env_variables, "to_be_replaced": to_be_raplaced_keys, }