当前位置: 首页>>代码示例>>Python>>正文


Python Product.set_preferred_listing方法代码示例

本文整理汇总了Python中product.Product.set_preferred_listing方法的典型用法代码示例。如果您正苦于以下问题:Python Product.set_preferred_listing方法的具体用法?Python Product.set_preferred_listing怎么用?Python Product.set_preferred_listing使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在product.Product的用法示例。


在下文中一共展示了Product.set_preferred_listing方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: EagleManagerTestCase

# 需要导入模块: from product import Product [as 别名]
# 或者: from product.Product import set_preferred_listing [as 别名]
class EagleManagerTestCase(unittest.TestCase):
	def setUp(self):
		unittest.TestCase.setUp(self)
		from product import *
		from part import Part
		from bom import BOM
		
		self.wspace = Workspace('DB Tests', os.path.join(os.getcwd(), 'testfixtures', 'dbtests.sqlite'))
		
		
		self.test_product = Product('TDK Corporation', 'C1608X5R1E105K', 'general_B11.pdf', 'CAP CER 1UF 25V 10% X5R 0603', '0603 (1608 Metric)')
		self.prices_ct = dict({10 : 0.09000, 100 : 0.04280, 250 : 0.03600, 500 : 0.03016, 1000 : 0.02475})
		self.prices_tr = dict({4000 : 0.01935, 8000 : 0.01800, 12000 : 0.01710, 280000 : 0.01620, 100000 : 0.01227})
		self.prices_dr = dict({10 : 0.09000, 100 : 0.04280, 250 : 0.03600, 500 : 0.03016, 1000 : 0.02475})
		self.test_listing_ct = Listing(VENDOR_DK, '445-5146-1-ND', 'C1608X5R1E105K', self.prices_ct, 566342, 'Cut Tape (CT)', 0, 'Capacitors', 'Ceramic', 'C')
		self.test_listing_tr = Listing(VENDOR_DK, '445-5146-2-ND', 'C1608X5R1E105K', self.prices_tr, 552000, 'Tape & Reel (TR)', 0, 'Capacitors', 'Ceramic', 'C')
		self.test_listing_dr = Listing(VENDOR_DK, '445-5146-6-ND', 'C1608X5R1E105K', self.prices_dr, 566342, 'Digi-Reel', 7, 'Capacitors', 'Ceramic', 'C')
		self.test_product.listings[self.test_listing_ct.key()] = self.test_listing_ct
		self.test_product.listings[self.test_listing_tr.key()] = self.test_listing_tr
		self.test_product.listings[self.test_listing_dr.key()] = self.test_listing_dr
		self.part_attribs = dict({'TOL' : '10%', 'VOLT' : '25V', 'TC' : 'X5R'})
		
		
	def test_db(self):
		#try:
		self.wspace.create_tables()
		from product import Product, Listing
		from part import Part
		from bom import BOM
		tables = []
		cur = self.wspace.memory.cursor()
		for row in cur.execute("SELECT name FROM sqlite_master WHERE type='table' ORDER BY name"):
			tables.append(row[0])
		
		cur.close()
		
		assert 'products' in tables
		assert 'parts' in tables
		assert 'part_attributes' in tables
		assert 'listings' in tables
		assert 'projects' in tables
		assert 'pricebreaks' in tables
		assert 'preferred_listings' in tables
		
		self.test_BOM = BOM.new_project('dbtests', 'Databse Unit tests', '', self.wspace.memory)
		self.wspace.projects = self.wspace.list_projects()
		
		assert len(self.wspace.projects) == 1
		assert 'dbtests' in self.wspace.projects
		
		self.test_part = Part('C1', self.test_BOM, '1uF', 'C-USC0603', 'C0603', 'CAPACITOR, American symbol', self.test_product, self.part_attribs)
		
		self.test_product.insert(self.wspace.memory)
		self.test_listing_ct.insert(self.wspace.memory)
		self.test_listing_tr.insert(self.wspace.memory)
		self.test_listing_dr.insert(self.wspace.memory)
		preferred_listing = self.test_product.get_preferred_listing(self.test_BOM, self.wspace.memory)
		assert preferred_listing is None
		self.test_product.set_preferred_listing(self.test_BOM, self.test_listing_ct, self.wspace.memory)
		preferred_listing = self.test_product.get_preferred_listing(self.test_BOM, self.wspace.memory)
		assert preferred_listing is not None
		assert preferred_listing.key() == self.test_listing_ct.key()
		self.test_product.set_preferred_listing(self.test_BOM, self.test_listing_dr, self.wspace.memory)
		preferred_listing = self.test_product.get_preferred_listing(self.test_BOM, self.wspace.memory)
		assert preferred_listing is not None
		assert preferred_listing.key() == self.test_listing_dr.key()
		self.test_part.insert(self.wspace.memory)
		
		# Product.select_by_pn fetches listings for the product, and fetch_listings fetches the price dicts
		ret_products = Product.select_by_pn(self.test_product.manufacturer_pn, self.wspace.memory)
		assert self.test_product.is_in_db(self.wspace.memory)
				
		# Should only return one result:
		assert len(ret_products) == 1
		
		# Product.equals() calls Listing.equals() as part of the check
		assert len (Listing.select_by_vendor_pn(self.test_listing_ct.vendor_pn, self.wspace.memory)) == 1
		assert len (Listing.select_by_vendor_pn(self.test_listing_tr.vendor_pn, self.wspace.memory)) == 1
		assert len (Listing.select_by_vendor_pn(self.test_listing_dr.vendor_pn, self.wspace.memory)) == 1
		assert len (Listing.select_by_manufacturer_pn(self.test_product.manufacturer_pn, self.wspace.memory)) == 3
		assert self.test_product.equals(ret_products[0])
		
		assert self.test_part.has_attribute('TOL', self.wspace.memory)
		assert self.test_part.has_attribute('VOLT', self.wspace.memory)
		assert self.test_part.has_attribute('TC', self.wspace.memory)
		ret_parts = Part.select_by_name(self.test_part.name, self.wspace.memory, self.test_BOM)
		try:
			assert len(ret_parts) == 1
		except AssertionError:
			print 'Assertion failed: assert len(ret_parts) == 1'
			print 'len(ret_parts): ', len(ret_parts)
			raise AssertionError
		assert self.test_part.equals(ret_parts[0])
		assert self.test_part.is_in_db(self.wspace.memory)
		ret_parts = self.test_BOM.select_parts_by_name(self.test_part.name, self.wspace.memory)
		assert len(ret_parts) == 1
		assert self.test_part.equals(ret_parts[0])
		
		self.test_part.delete(self.wspace.memory)
		assert len(self.test_BOM.select_parts_by_name(self.test_part.name, self.wspace.memory)) == 0
#.........这里部分代码省略.........
开发者ID:jbaker0428,项目名称:Eagle-BOM-Manager,代码行数:103,代码来源:tests.py


注:本文中的product.Product.set_preferred_listing方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。