本文整理汇总了Python中spreadsheetimport.SpreadsheetImport.analyze方法的典型用法代码示例。如果您正苦于以下问题:Python SpreadsheetImport.analyze方法的具体用法?Python SpreadsheetImport.analyze怎么用?Python SpreadsheetImport.analyze使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类spreadsheetimport.SpreadsheetImport
的用法示例。
在下文中一共展示了SpreadsheetImport.analyze方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testImportSimple
# 需要导入模块: from spreadsheetimport import SpreadsheetImport [as 别名]
# 或者: from spreadsheetimport.SpreadsheetImport import analyze [as 别名]
def testImportSimple(self):
no_signals()
testimport = SpreadsheetImport(StringIO(csv_file), [self.collection])
self.assertEqual(0, self.collection.records.count())
testimport.analyze()
dc = dict(
identifier=Field.objects.get(name='identifier', standard__prefix='dc'),
title=Field.objects.get(name='title', standard__prefix='dc'),
creator=Field.objects.get(name='creator', standard__prefix='dc'),
coverage=Field.objects.get(name='coverage', standard__prefix='dc'),
)
testimport.mapping = {
'ID': dc['identifier'],
'Filename': None,
'Title': dc['title'],
'Creator': dc['creator'],
'Location': dc['coverage'],
}
testimport.name_field = 'ID'
self.assertNotEqual(None, testimport.get_identifier_field())
testimport.run()
self.assertEquals(2, self.collection.records.count())
r1 = self.collection.records.get(name='A001'.lower())
self.assertEqual('A001', r1.fieldvalue_set.get(field=dc['identifier']).value)
示例2: test_split_values_import
# 需要导入模块: from spreadsheetimport import SpreadsheetImport [as 别名]
# 或者: from spreadsheetimport.SpreadsheetImport import analyze [as 别名]
def test_split_values_import(self):
testimport = SpreadsheetImport(
StringIO("ID,Split,NoSplit\nA999,a;b,a;b"), [self.collection])
testimport.analyze()
dc = dict(
identifier=Field.objects.get(
name='identifier', standard__prefix='dc'),
title=Field.objects.get(name='title', standard__prefix='dc'),
creator=Field.objects.get(name='creator', standard__prefix='dc'),
)
testimport.mapping = {
'ID': dc['identifier'],
'Split': dc['title'],
'NoSplit': dc['creator'],
}
testimport.name_field = 'ID'
testimport.separate_fields = {
'Split': True,
}
testimport.run()
r = self.collection.records.get(name='A999'.lower())
self.assertEqual(
'a',
r.fieldvalue_set.filter(field=testimport.mapping['Split'])[0].value
)
self.assertEqual(
'b',
r.fieldvalue_set.filter(field=testimport.mapping['Split'])[1].value
)
self.assertEqual(
'a;b',
r.fieldvalue_set.filter(
field=testimport.mapping['NoSplit'])[0].value
)
示例3: test_no_bom
# 需要导入模块: from spreadsheetimport import SpreadsheetImport [as 别名]
# 或者: from spreadsheetimport.SpreadsheetImport import analyze [as 别名]
def test_no_bom(self):
"""Make sure the import can handle the lack of BOM at the beginning
of some UTF-8 files"""
testimport = SpreadsheetImport(StringIO(csv_file), [self.collection])
testimport.analyze()
self.assertTrue('ID' in testimport.mapping)
self.assertTrue('Filename' in testimport.mapping)
self.assertTrue('Unused' in testimport.mapping)
self.assertTrue('Title' in testimport.mapping)
self.assertTrue('Creator' in testimport.mapping)
self.assertTrue('Location' in testimport.mapping)
示例4: analyze
# 需要导入模块: from spreadsheetimport import SpreadsheetImport [as 别名]
# 或者: from spreadsheetimport.SpreadsheetImport import analyze [as 别名]
def analyze(collections=None, separator=None, separate_fields=None, fieldset=None):
try:
with open(os.path.join(_get_scratch_dir(), _get_filename(request, file)), 'rU') as csvfile:
imp = SpreadsheetImport(csvfile, collections, separator=separator,
separate_fields=separate_fields, preferred_fieldset=fieldset)
return imp, imp.analyze()
except IOError:
raise Http404()
示例5: testImport
# 需要导入模块: from spreadsheetimport import SpreadsheetImport [as 别名]
# 或者: from spreadsheetimport.SpreadsheetImport import analyze [as 别名]
def testImport(self):
testimport = SpreadsheetImport(StringIO(csv_file), [self.collection])
self.assertFalse(testimport.analyzed)
data = testimport.analyze()
self.assertTrue(testimport.analyzed)
示例6: testNoBOM
# 需要导入模块: from spreadsheetimport import SpreadsheetImport [as 别名]
# 或者: from spreadsheetimport.SpreadsheetImport import analyze [as 别名]
def testNoBOM(self):
"""Make sure the import can handle the lack of BOM at the beginning of some UTF-8 files"""
no_signals()
testimport = SpreadsheetImport(StringIO(csv_file), [self.collection])
data = testimport.analyze()
self.assertTrue(testimport.mapping.has_key('ID'))
self.assertTrue(testimport.mapping.has_key('Filename'))
self.assertTrue(testimport.mapping.has_key('Unused'))
self.assertTrue(testimport.mapping.has_key('Title'))
self.assertTrue(testimport.mapping.has_key('Creator'))
self.assertTrue(testimport.mapping.has_key('Location'))
示例7: testBOM
# 需要导入模块: from spreadsheetimport import SpreadsheetImport [as 别名]
# 或者: from spreadsheetimport.SpreadsheetImport import analyze [as 别名]
def testBOM(self):
"""Make sure the import can handle the BOM at the beginning of some UTF-8 files"""
BOM = "\xef\xbb\xbf"
testimport = SpreadsheetImport(StringIO(BOM + csv_file), [self.collection])
data = testimport.analyze()
self.assertTrue(testimport.mapping.has_key('ID'))
self.assertTrue(testimport.mapping.has_key('Filename'))
self.assertTrue(testimport.mapping.has_key('Unused'))
self.assertTrue(testimport.mapping.has_key('Title'))
self.assertTrue(testimport.mapping.has_key('Creator'))
self.assertTrue(testimport.mapping.has_key('Location'))
示例8: test_analyze
# 需要导入模块: from spreadsheetimport import SpreadsheetImport [as 别名]
# 或者: from spreadsheetimport.SpreadsheetImport import analyze [as 别名]
def test_analyze(self):
testimport = SpreadsheetImport(StringIO(csv_file), [self.collection])
self.assertFalse(testimport.analyzed)
data = testimport.analyze()
self.assertTrue(testimport.analyzed)
self.assertEqual(2, len(data))
self.assertEqual('A001', data[0]['ID'][0])
self.assertEqual('a001.jpg', data[0]['Filename'][0])
self.assertEqual('Test', data[0]['Title'][0])
self.assertEqual('Knab, Andreas', data[0]['Creator'][0])
self.assertEqual('Harrisonburg, VA', data[0]['Location'][0])
self.assertEqual(None, data[0]['Unused'])
self.assertEqual('A002', data[1]['ID'][0])
self.assertEqual('a002.jpg', data[1]['Filename'][0])
self.assertEqual('Another Test', data[1]['Title'][0])
self.assertEqual('Andreas Knab;John Doe', data[1]['Creator'][0])
self.assertEqual('Virginia', data[1]['Location'][0])
self.assertEqual(None, data[1]['Unused'])
# These don't match anything
self.assertEqual(None, testimport.mapping['ID'])
self.assertEqual(None, testimport.mapping['Filename'])
self.assertEqual(None, testimport.mapping['Unused'])
# These should match standards fields
self.assertNotEqual(None, testimport.mapping['Title'])
self.assertNotEqual(None, testimport.mapping['Creator'])
self.assertNotEqual(None, testimport.mapping['Location'])
self.assertEqual(None, testimport.get_identifier_field())
# Map the ID field and try again
testimport.mapping['ID'] = Field.objects.get(
name='identifier', standard__prefix='dc')
self.assertEqual('ID', testimport.get_identifier_field())