def test_numeric_get_key(): T = {111: {'stuff': 'hi'}} m = dotted.get(T, '111.stuff') assert m == 'hi' m = dotted.get(T, '111.0.stuff') assert m != 'hi' # 111.0 == 111 m = dotted.get(T, '#"111.0".stuff') assert m == 'hi'
def test_numeric_get_slot(): T = {111: {'stuff': 'hi'}} m = dotted.get(T, '[111].stuff') assert m == 'hi' # 111.0 == 111 m = dotted.get(T, '[111.0].stuff') assert m == 'hi' # 111.0 == 111 m = dotted.get(T, '[#"111.0"].stuff') assert m == 'hi'
def generate(self, events, feed_name): data = [] logging.info("Exporting feed {} using CSV".format(feed_name)) for event in events: e_feed = event.to_feed(with_meta=True) temp_data = [] for field in self.fields: temp = dotted.get(e_feed, field) if isinstance(temp, (list, tuple)) and not field in self.to_unroll: temp = ', '.join(temp) temp_data.append(temp) data.extend(self.unroll(temp_data)) if os.path.isfile(self.filename): with open(self.filename, 'r') as file: try: csvread = csv.reader(file) next(csvread, None) original = set(map(tuple, csvread)) except: original = "" else: original = "" if original != set(map(tuple, data)): with open(self.filename, 'w', newline='') as outputfile: csvfile = csv.writer(outputfile) csvfile.writerow(self.headers) for row in data: csvfile.writerow(row) else: logging.debug("CSV file unchanged")
def generate(self, events, feed_name): data = [] logging.info("Exporting feed {} using screen".format(feed_name)) for event in events: e_feed = event.to_feed(with_meta=True) temp_data = [] for field in self.fields: temp = dotted.get(e_feed, field) if isinstance(temp, (list, tuple)) and not field in self.to_unroll: temp = ', '.join(temp) temp_data.append(temp) data.extend(self.unroll(temp_data)) print(columnar(data, self.headers, no_borders=True))
def test_invert_get(): r = dotted.get({'hello': 'there'}, '-hello') assert r == 'there' r = dotted.get([], '-[0]') assert r is None