def test_numpy_array(self): try: import numpy as np except Exception: raise unittest.SkipTest("Skipping numpy serialization testing...") x = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) x = recursive_dict(x) self.assertEqual(x, [[1, 2, 3], [4, 5, 6], [7, 8, 9]])
def test_numpy_array(self): try: import numpy as np except: raise unittest.SkipTest("Skipping numpy serialization testing...") x = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) x = recursive_dict(x) self.assertEqual(x, [[1, 2, 3], [4, 5, 6], [7, 8, 9]])
def init_yaml(args): fields = (("host", "localhost"), ("port", 27017), ("name", "fireworks"), ("username", None), ("password", None), ("ssl_ca_file", None)) doc = {} print("Please supply the following configuration values") print("(press Enter if you want to accept the defaults)\n") for k, v in fields: val = input("Enter {} (default: {}) : ".format(k, v)) doc[k] = val if val else v doc["port"] = int(doc["port"]) # enforce the port as an int with open(args.config_file, "w") as f: import yaml doc = LaunchPad.from_dict(doc).to_dict() doc = recursive_dict(doc, preserve_unicode=False) # drop unicode yaml.dump(doc, f) print("\nConfiguration written to {}!".format(args.config_file))
def init_yaml(args): fields = ( ("host", "localhost"), ("port", 27017), ("name", "fireworks"), ("username", None), ("password", None)) doc = {} print("Please supply the following configuration values") print("(press Enter if you want to accept the defaults)\n") for k, v in fields: val = input("Enter {} (default: {}) : ".format(k, v)) doc[k] = val if val else v doc["port"] = int(doc["port"]) # enforce the port as an int with open(args.config_file, "w") as f: import yaml doc = LaunchPad.from_dict(doc).to_dict() doc = recursive_dict(doc, preserve_unicode=False) # drop unicode yaml.dump(doc, f) print("\nConfiguration written to {}!".format(args.config_file))
def get_output_func(format): if format == "json": return lambda x: json.dumps(x, default=DATETIME_HANDLER, indent=4) else: return lambda x: yaml.dump(recursive_dict(x, preserve_unicode=False), default_flow_style=False)
def _decorator(self, *args, **kwargs): m_dict = func(self, *args, **kwargs) m_dict = fw_serializers.recursive_dict(m_dict) return m_dict