Exemplo n.º 1
0
    def test_put_get_delete_types(self):
        table = f"test-table-{uuid4()}"

        row = tnu_table.Row(name=f"{uuid4()}",
                            attributes=dict(foo=f"{uuid4()}",
                                            bar=f"{uuid4()}"))
        with self.subTest("put", type="row"):
            tnu_table.put_row(table, row)
            self.assertEqual(row, tnu_table.get_row(table, row))
        with self.subTest("del", type="row"):
            tnu_table.del_row(table, row)
            self.assertIsNone(tnu_table.get_row(table, row))
            tnu_table.del_row(table, row)  # this should work twice

        attributes = dict(foo=f"{uuid4()}", bar=f"{uuid4()}")
        with self.subTest("put", type="dict"):
            name = tnu_table.put_row(table, attributes)
            self.assertEqual(attributes,
                             tnu_table.get_row(table, name).attributes)
            with self.assertRaises(TypeError):
                tnu_table.put_row(table, dict(foo=time))
        with self.subTest("del", type="dict"):
            tnu_table.del_row(table, name)
            self.assertIsNone(tnu_table.get_row(table, name))
            tnu_table.del_row(table, name)  # this should work twice
Exemplo n.º 2
0
    def _gen_rows(self, number_of_rows: int):
        def _rand_value(types={str, int, float, bool, list, dict, None}):
            t = random.choice(list(types))
            if str == t:
                val = f"{uuid4()}"
            elif int == t:
                val = random.randint(0, 997)
                val *= (-1 + random.choice((0, 2)))
            elif float == t:
                val = random.random()
            elif bool == t:
                val = bool(random.randint(0, 1))
            elif list == t:
                list_member_type = random.choice(list(types - {list} - {None}))
                val = [
                    _rand_value([list_member_type])
                    for _ in range(random.randint(1, 4))
                ]
            elif dict == t:
                val = dict(foo="a", bar=3)
            elif None is t:
                val = None
            return val

        all_column_headers = [["foo", "bar", "fubar", "snafu"], ["foo", "bar"],
                              ["bar"]]
        rows = list()
        for _ in range(number_of_rows):
            column_headers = random.choice(all_column_headers)
            attributes = {c: _rand_value() for c in column_headers}
            row_name = f"{uuid4()}"
            rows.append(tnu_table.Row(row_name, attributes))
        return rows
 def setUpClass(cls):
     cls.table = f"test-{uuid4()}"
     cls.table_data = list()
     with tnu_table.Writer(cls.table) as writer:
         for _ in range(11):
             row = tnu_table.Row(f"{uuid4()}",
                                 dict(a=f"{uuid4()}", b=f"{uuid4()}"))
             writer.put_row(row)
             e = row.attributes.copy()
             e['entity_id'] = row.name
             cls.table_data.append(e)
     cls.columns = list(row.attributes.keys())
Exemplo n.º 4
0
def put_row(args: argparse.Namespace):
    """
    Put a row.
    Example:
    tnu table put-row \\
    --table abbrv_merge_input \\
    --id 1 \\
    bucket=fc-9169fcd1-92ce-4d60-9d2d-d19fd326ff10 \\
    input_keys=test_vcfs/a.vcf.gz,test_vcfs/b.vcf.gz \\
    output_key=foo.vcf.gz
    """
    args.workspace, args.workspace_namespace = Config.resolve(args.workspace, args.workspace_namespace)
    attributes = dict()
    for pair in args.data:
        key, val = pair.split("=")
        attributes[key] = val
    row = tnu_table.Row(name=args.row or f"{uuid4()}", attributes=attributes)
    tnu_table.put_row(args.table, row, args.workspace, args.workspace_namespace)
Exemplo n.º 5
0
 def test_row_name_types(self):
     tnu_table.Row(name="foo", attributes=dict())
     with self.assertRaises(AssertionError):
         tnu_table.Row(name=1, attributes=dict())