How to use get_or_create_path method in localstack

Best Python code snippet using localstack_python

relationship_test.py

Source:relationship_test.py Github

copy

Full Screen

...158 def test_relate(self):159 alice, bob = self.graph.create(160 {"name": "Alice"}, {"name": "Bob"}161 )162 rel = alice.get_or_create_path("KNOWS", bob).relationships[0]163 assert rel is not None164 assert isinstance(rel, Relationship)165 assert rel.start_node == alice166 assert rel.type == "KNOWS"167 assert rel.end_node == bob168 def test_repeated_relate(self):169 alice, bob = self.graph.create(170 {"name": "Alice"}, {"name": "Bob"}171 )172 rel1 = alice.get_or_create_path("KNOWS", bob).relationships[0]173 assert rel1 is not None174 assert isinstance(rel1, Relationship)175 assert rel1.start_node == alice176 assert rel1.type == "KNOWS"177 assert rel1.end_node == bob178 rel2 = alice.get_or_create_path("KNOWS", bob).relationships[0]179 assert rel1 == rel2180 rel3 = alice.get_or_create_path("KNOWS", bob).relationships[0]181 assert rel1 == rel3182 def test_relate_with_no_end_node(self):183 alice, = self.graph.create(184 {"name": "Alice"}185 )186 rel = alice.get_or_create_path("KNOWS", None).relationships[0]187 assert rel is not None188 assert isinstance(rel, Relationship)189 assert rel.start_node == alice190 assert rel.type == "KNOWS"191 def test_relate_with_data(self):192 alice, bob = self.graph.create(193 {"name": "Alice"}, {"name": "Bob"}194 )195 rel = alice.get_or_create_path(("KNOWS", {"since": 2006}), bob).relationships[0]196 assert rel is not None197 assert isinstance(rel, Relationship)198 assert rel.start_node == alice199 assert rel.type == "KNOWS"200 assert rel.end_node == bob201 assert "since" in rel202 assert rel["since"] == 2006203 def test_relate_with_null_data(self):204 alice, bob = self.graph.create(205 {"name": "Alice"}, {"name": "Bob"}206 )207 rel = alice.get_or_create_path(("KNOWS", {"since": 2006, "dummy": None}), bob).relationships[0]208 assert rel is not None209 assert isinstance(rel, Relationship)210 assert rel.start_node == alice211 assert rel.type == "KNOWS"212 assert rel.end_node == bob213 assert "since" in rel214 assert rel["since"] == 2006215 assert rel["dummy"] is None216 def test_repeated_relate_with_data(self):217 alice, bob = self.graph.create(218 {"name": "Alice"}, {"name": "Bob"}219 )220 rel1 = alice.get_or_create_path(("KNOWS", {"since": 2006}), bob).relationships[0]221 assert rel1 is not None222 assert isinstance(rel1, Relationship)223 assert rel1.start_node == alice224 assert rel1.type == "KNOWS"225 assert rel1.end_node == bob226 rel2 = alice.get_or_create_path(("KNOWS", {"since": 2006}), bob).relationships[0]227 assert rel1 == rel2228 rel3 = alice.get_or_create_path(("KNOWS", {"since": 2006}), bob).relationships[0]229 assert rel1 == rel3230 # disabled test known to fail due to server issues231 #232 #def test_relate_with_list_data(self):233 # alice, bob = self.graph.create(234 # {"name": "Alice"}, {"name": "Bob"}235 # )236 # rel, = self.graph.get_or_create_relationships((alice, "LIKES", bob, {"reasons": ["looks", "wealth"]}))237 # assert rel is not None238 # assert isinstance(rel, Relationship)239 # assert rel.start_node == alice240 # self.assertEqual("LIKES", rel.type)241 # assert rel.end_node == bob242 # self.assertTrue("reasons" in rel)243 # self.assertEqual("looks", rel["reasons"][0])244 # self.assertEqual("wealth", rel["reasons"][1])245 def test_complex_relate(self):246 alice, bob, carol, dave = self.graph.create(247 {"name": "Alice"}, {"name": "Bob"},248 {"name": "Carol"}, {"name": "Dave"}249 )250 batch = WriteBatch(self.graph)251 batch.get_or_create_path(alice, ("IS~MARRIED~TO", {"since": 1996}), bob)252 #batch.get_or_create((alice, "DISLIKES", carol, {"reasons": ["youth", "beauty"]}))253 batch.get_or_create_path(alice, ("DISLIKES!", {"reason": "youth"}), carol)254 rels1 = batch.submit()255 assert rels1 is not None256 assert len(rels1) == 2257 batch = WriteBatch(self.graph)258 batch.get_or_create_path(bob, ("WORKS WITH", {"since": 2004, "company": "Megacorp"}), carol)259 #batch.get_or_create((alice, "DISLIKES", carol, {"reasons": ["youth", "beauty"]}))260 batch.get_or_create_path(alice, ("DISLIKES!", {"reason": "youth"}), carol)261 batch.get_or_create_path(bob, ("WORKS WITH", {"since": 2009, "company": "Megacorp"}), dave)262 rels2 = batch.submit()263 assert rels2 is not None264 assert len(rels2) == 3265 assert rels1[1] == rels2[1]266def test_rel_cannot_have_multiple_types():267 try:268 _ = Rel("LIKES", "HATES")269 except ValueError:270 assert True271 else:272 assert False273def test_relationship_exists_will_raise_non_404_errors(graph):274 with patch.object(_Resource, "get") as mocked:275 error = GraphError("bad stuff happened")...

Full Screen

Full Screen

helpers.py

Source:helpers.py Github

copy

Full Screen

...14 """BBox transform"""15 x2 = box[0] + box[2]16 y2 = box[1] + box[3]17 return np.array([box[0], box[1], x2, y2])18def get_or_create_path(path_string, parents=True):19 """ Get path object from string, create if non-existing"""20 p = Path(path_string)21 if not p.exists():22 p.mkdir(parents=parents)23 return p24class Timer(object):25 """26 Simple timer tool27 """28 def __init__(self, history=500):29 self._time = 0.30 self._total_time = 0.31 self._total_calls = 0.32 self._history = history33 def tic(self):34 self._time = time.time()35 def toc(self):36 time_passed = time.time() - self._time37 self._total_time += time_passed38 self._total_calls += 139 return time_passed40 def average(self):41 av = 042 if self._total_calls > 0:43 av = self._total_time / self._total_calls44 if self._total_calls > self._history:45 self._total_calls = 046 self._total_time = 047 return av48class RunningAverages(object):49 def __init__(self, num_of_averages, max_length=100):50 self._averages = [RunningAverage(length=max(max_length, 100)) for _ in range(num_of_averages)]51 def __call__(self, *args, **kwargs):52 return self._averages53 def update(self, values):54 assert isinstance(values, (list, tuple)), 'values to average must be a list or a tuple'55 assert len(values) == len(self._averages)56 for l, av in zip(values, self._averages):57 av.update(l)58class RunningAverage(object):59 """60 Calculate a running average of a variable61 """62 def __init__(self, length=None):63 self._num_steps = 064 self._sum_values = 0.65 self._length = length66 def __call__(self):67 if self._num_steps < 1:68 return 0.69 return self._sum_values / self._num_steps70 def update(self, x):71 if self._length and self._num_steps >= self._length:72 self._num_steps = 073 self._sum_values = 074 self._num_steps += 175 self._sum_values += float(x)76 def reset(self):77 self.__init__()78class Logger(object):79 _log_file_name = 'log.txt'80 def __init__(self, log_dir):81 self._log_file = self._file_from_path(log_dir)82 self._orig_output = sys.stdout83 self._lines_written = 084 return85 def __call__(self, print_string, show=True):86 sys.stdout = self._log_file87 log_string = '%s %s' % (_log_time_stamp(), str(print_string))88 print (log_string)89 self._log_file.flush()90 sys.stdout = self._orig_output91 self._lines_written += 192 if show:93 print(print_string)94 def _file_from_path(self, log_dir):95 log_file = Path(log_dir) / self._log_file_name96 file_obj = _check_and_get_file_obj(log_file)97 return file_obj98 def close(self):99 self.__call__('Finished Logging %d lines written' % self._lines_written)100 self._log_file.close()101def dense_time_stamp():102 return strftime("%d_%m_%Y_%H%M%S", gmtime())103def _log_time_stamp():104 return strftime("[%d-%m-%Y-%H:%M:%S]", gmtime())105def _check_and_get_wd_path_obj(wd):106 p = Path(wd)107 if not p.exists():108 p.mkdir(parents=True)109 return p110def _check_and_get_file_obj(fpath):111 p = Path(fpath)112 if not p.parent.exists():113 p.parent.mkdir(parents=True)114 if p.is_file():115 return p.open('ab')116 return p.open('wb')117def clean_word(word):118 """Remove punctuation marks and redundant spaces from a word"""119 exclude = set(punctuation)120 s = ''.join(ch for ch in word if ch not in exclude)121 s = s.strip().lower()122 return s123class TensorBoardFiles(object):124 LOGS = 'logs'125 def __init__(self, experiment_dir, prefix, sess):126 import tensorflow as tf127 if prefix:128 summary_writer = tf.summary.FileWriter(129 str(get_or_create_path(path_string=experiment_dir / self.LOGS / ('%s_%s' % (prefix, dense_time_stamp())))), sess.graph)130 fake_summary_writer = tf.summary.FileWriter(131 str(get_or_create_path(path_string=experiment_dir / self.LOGS / ('fake_%s_%s' % (prefix, dense_time_stamp())))), sess.graph)132 else:133 summary_writer = tf.summary.FileWriter(str(get_or_create_path(path_string=experiment_dir / 'logs' / dense_time_stamp())), sess.graph)134 fake_summary_writer = tf.summary.FileWriter(135 str(get_or_create_path(path_string=experiment_dir / self.LOGS / ('fake_%s' % dense_time_stamp()))), sess.graph)136 self.real = summary_writer...

Full Screen

Full Screen

uploader.py

Source:uploader.py Github

copy

Full Screen

1import os2from settings.settings import MEDIA_ROOT, BASE_DIR3class Uploader:4 @staticmethod5 def get_or_create_path(name):6 try:7 os.mkdir(str(name))8 except Exception as e:9 print(e)10 finally:11 return str(name)12 @staticmethod13 def get_path(owner, owner_type, picture_type, filename, base_for_file=''):14 os.chdir(MEDIA_ROOT)15 os.chdir(Uploader.get_or_create_path(owner_type))16 os.chdir(Uploader.get_or_create_path(owner))17 if picture_type:18 os.chdir(Uploader.get_or_create_path(picture_type))19 if base_for_file:20 os.chdir(Uploader.get_or_create_path(base_for_file))...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful