move unserializable_attributes to static attribute

This commit is contained in:
12v
2023-09-10 15:44:26 +01:00
parent 107e58d84c
commit d3c4bc58fe
6 changed files with 7 additions and 14 deletions

View File

@@ -2,7 +2,7 @@ import requests
import time
import os
import functools
from ratelimit import limits, RateLimitException, sleep_and_retry
from ratelimit import limits, sleep_and_retry
access_token = ""
username = ""

View File

@@ -2,9 +2,10 @@ import sugartrail
import IPython
import json
import functools
import pandas as pd
class Network:
_unserialisable_attributes = ['hop', '_file', 'progress']
"""Class represents a network of connected companies, officers and
addresses. Class contains methods to build network of user defined size from
a single seed company, officer or address."""
@@ -142,7 +143,7 @@ class Network:
return company_table
@property
def address(self, value):
def address(self):
"""address property representing seed address."""
return self._address
@@ -212,7 +213,7 @@ class Network:
def save(self, filename, location='../assets/networks/'):
"""Saves network in JSON format to '../assets/networks/'."""
network_data = {k: v for k, v in self.__dict__.items() if k not in ['hop', 'file', 'progress']}
network_data = {k: v for k, v in self.__dict__.items() if k not in self._unserialisable_attributes}
saved_network = json.dumps(network_data)
f = open(location + f'{filename}', 'w')
f.write(saved_network)

View File

@@ -1,8 +1,6 @@
from ipywidgets import HTML, Widget, Layout, Output, VBox, HBox, Textarea
from ipyleaflet import Map, Marker, MarkerCluster, AwesomeIcon, AntPath, Popup
from datetime import datetime
import functools
import math
def build_map(network, clear_widget=True):
"""Generates map and table for displaying paths for input network data."""

View File

@@ -1,7 +1,5 @@
from sugartrail import api
import requests
import pandas as pd
import random
import urllib
import regex as re
import collections
@@ -171,7 +169,6 @@ def build_address_history(company_id):
addresses.append(entry)
return addresses
else:
address_history = []
entry = {}
for k, key in enumerate(["date_of_creation","date_of_cessation","registered_office_address"]):
if key in company_info:
@@ -184,7 +181,6 @@ def build_address_history(company_id):
entry["lon"] = ""
return [entry]
else:
address_history = []
entry = {}
for k, key in enumerate(["date_of_creation","date_of_cessation","registered_office_address"]):
if key in company_info:

View File

@@ -1,4 +1,3 @@
import sugartrail
import IPython
class Progress:

View File

@@ -1,5 +1,4 @@
import sugartrail
import pytest
import json
# test 1: network initialised without auth and without arguments:
@@ -47,7 +46,7 @@ def test_file_init_without_auth():
with open('./assets/networks/domain_corp_network.json') as f:
network_json = json.load(f)
for key in network.__dict__.keys():
if key not in ['hop', '_file', 'progress']:
if key not in sugartrail.base.Network._unserialisable_attributes:
assert network.__dict__[key] == network_json[key]
# test 5: network loads network from file without auth:
@@ -58,5 +57,5 @@ def test_file_load_without_auth():
with open('./assets/networks/domain_corp_network.json') as f:
network_json = json.load(f)
for key in network.__dict__.keys():
if key not in ['hop', '_file', 'progress']:
if key not in sugartrail.base.Network._unserialisable_attributes:
assert network.__dict__[key] == network_json[key]