def test_labelcols(self): """Test whether extra labels are created """ codes = self.export(labelcols=True) self.assertTrue(hasattr(head(codes.values()), "labelnl")) self.assertTrue(hasattr(head(codes.values()), "labelde")) self.assertFalse(hasattr(head(codes.values()), "label?")) nl_labels = list(filter(bool, [c.labelnl for c in codes.values()])) self.assertEqual(1, len(nl_labels)) self.assertEqual("Een", nl_labels[0]) de_labels = list(filter(bool, [c.labelde for c in codes.values()])) self.assertEqual(1, len(de_labels)) self.assertEqual("Ein", de_labels[0]) # Exporting structure format, thus no parent column self.assertFalse(hasattr(head(codes.values()), "parent"))
def test_head(self): for input, filter, output in ( ([1, 2, 3], None, 1), ([], None, None), ([1, 2, 3, 4], lambda x: not x % 2, 2), ([4, 3, 2, 1], lambda x: not x % 2, 4), ([3, 1], lambda x: not x % 2, None), ): self.assertEqual(output, toolkit.head(input, filter)) self.assertEqual(output, toolkit.head(tuple(input), filter)) self.assertEqual(output, toolkit.head((i for i in input), filter)) s = set(input) out = toolkit.head(s, filter) if out is None: if filter: self.assertTrue(not [x for x in s if filter(x)]) else: self.assertFalse(s) else: self.assertTrue(out in s, "%r not in %s" % (out, s)) if filter: self.assertTrue(filter(out))
def test_language(self): """Test if exporter renders correct labels""" codes = self.export(language=self.de) # Exporting structure format, thus no parent column self.assertFalse(hasattr(head(codes.values()), "parent_id")) # Should export default label, e.g. "A" de_code = codes[self.codes_list[0].id] self.assertIn("A", map(str, self.codes_list)) # should not put 'languaged' labels in codeX columns self.assertNotIn("Ein", (de_code.code1, de_code.code2, de_code.code3)) nl_code = codes[self.codes_list[1].id] self.assertNotIn("Een", (nl_code.code1, nl_code.code2, nl_code.code3))
def test_head(self): for input, filter, output in ( ([1,2,3], None, 1), ([], None, None), ([1,2,3,4], lambda x : not x%2, 2), ([4,3,2,1], lambda x : not x%2, 4), ([3,1], lambda x : not x%2, None), ): self.assertEqual(output, toolkit.head(input, filter)) self.assertEqual(output, toolkit.head(tuple(input), filter)) self.assertEqual(output, toolkit.head((i for i in input), filter)) s = set(input) out = toolkit.head(s, filter) if out is None: if filter: self.assertTrue(not [x for x in s if filter(x)]) else: self.assertFalse(s) else: self.assertTrue(out in s, "%r not in %s" % (out, s)) if filter: self.assertTrue(filter(out))
def test_indented(self): """Test indented format.""" codes = self.export() # Depth of tree is 3, so we need exactly three columns self.assertTrue(hasattr(head(codes.values()), "code1")) self.assertTrue(hasattr(head(codes.values()), "code2")) self.assertTrue(hasattr(head(codes.values()), "code3")) self.assertFalse(hasattr(head(codes.values()), "code4")) # Check other properties self.assertTrue(hasattr(head(codes.values()), "uuid")) self.assertTrue(hasattr(head(codes.values()), "code_id")) self.assertFalse(hasattr(head(codes.values()), "parent")) # 2 roots self.assertEqual(2, len(list(filter(bool, [c.code1 for c in codes.values()])))) # 3 'sub'roots self.assertEqual(3, len(list(filter(bool, [c.code2 for c in codes.values()])))) # 2 'subsub'roots self.assertEqual(2, len(list(filter(bool, [c.code3 for c in codes.values()]))))
def get_columns(self): if not (self.colnames or self.rows): return [] colnames = self.colnames or range(len(toolkit.head(self.rows))) return [idlabel.IDLabel(i, colname) for (i, colname) in enumerate(colnames)]
def test_head(self): it = iter(range(10)) self.assertEqual(0, toolkit.head(it)) self.assertEqual(1, toolkit.head([1, 2]))
def test_parent(self): """Test parent format.""" codes = self.export(structure="parent") self.assertTrue(hasattr(head(codes.values()), "parent_id"))
def getColumns(self): if not (self.colnames or self.rows): return [] colnames = self.colnames or range(len(toolkit.head(self.rows))) return [ idlabel.IDLabel(i, colname) for (i, colname) in enumerate(colnames) ]