How to use with_value method in Sure

Best Python code snippet using sure_python

option.py

Source:option.py Github

copy

Full Screen

1#2# Copyright (c) 2006-2013, Prometheus Research, LLC3#4"""5:mod:`htsql.ctl.option`6=======================7This module defines script options.8"""9from ..core.util import maybe10from ..core.validator import Validator, StrVal, UIntVal, ExtensionVal11import re12class Option:13 """14 Describes a script option.15 `attribute` (a string)16 The name of the routine attribute. When the routine is17 initialized, the value of the option is assigned to the18 attribute.19 `short_name` (a string or ``None``)20 The abbrebiated form of the option (a dash + a character).21 `long_name` (a string or ``None``)22 The full form of the option (two dashes + the option name).23 `with_value` (Boolean)24 If set, the option requires a parameter.25 `value_name` (a string or ``None``)26 The name of the option parameter.27 `validator` (:class:`htsql.validator.Validator` or ``None``)28 The validator for the option parameter.29 `default`30 The default value of the parameter; ``None`` if not set.31 `is_list` (Boolean)32 If set, the option could be specified more than one time.33 The combined values are stored as a list; the default34 value for a list option is ``[]``.35 `hint` (a string or ``None``)36 A one-line description of the option.37 When an option does not require a parameter, the value of the38 option is either ``False`` or ``True``. If the option is39 provided in the command line, the value is ``True``; otherwise,40 the value is ``False``.41 When an option requires a parameter, the value of the option42 is determined by the parameter and the attributes `validator`43 and `default`. If the option is not provided, its value is44 equal to `default`. If the option is provided, its value is45 the value of the option parameter normalized by application46 of `validator`.47 """48 def __init__(self, attribute,49 short_name=None, long_name=None,50 with_value=False, value_name=None,51 validator=None, default=None,52 is_list=False, hint=None):53 # Sanity check on the arguments.54 assert isinstance(attribute, str)55 assert re.match(r'^[a-zA-Z_][0-9a-zA-Z_]*$', attribute)56 assert isinstance(short_name, maybe(str))57 if short_name is not None:58 assert re.match(r'^-[0-9a-zA-Z]$', short_name)59 assert isinstance(long_name, maybe(str))60 if long_name is not None:61 assert re.match(r'^--[0-9a-zA-Z][0-9a-zA-Z-]+$', long_name)62 assert short_name is not None or long_name is not None63 assert isinstance(with_value, bool)64 assert isinstance(value_name, maybe(str))65 assert isinstance(validator, maybe(Validator))66 if with_value:67 assert validator is not None68 else:69 assert value_name is None70 assert validator is None71 assert default is None72 assert isinstance(is_list, bool)73 if is_list:74 assert default is None75 assert isinstance(hint, maybe(str))76 self.attribute = attribute77 self.short_name = short_name78 self.long_name = long_name79 self.with_value = with_value80 self.value_name = value_name81 self.validator = validator82 self.default = default83 self.is_list = is_list84 self.hint = hint85 def get_hint(self):86 """87 Returns a short one-line description of the option.88 """89 return self.hint90 def get_signature(self):91 """92 Returns the signature of the option parameters.93 """94 # The option signature has one of the forms:95 # {short_name} {PARAMETER}96 # {long_name} {PARAMETER}97 # or 98 # {short_name} [{long_name}] {PARAMETER}99 # A trailing `[+]` is added for repeatable options.100 if self.short_name is not None:101 signature = self.short_name102 if self.long_name is not None:103 signature = "%s [%s]" % (signature, self.long_name)104 else:105 signature = self.long_name106 if self.with_value:107 if self.value_name is not None:108 parameter = self.value_name109 else:110 parameter = self.attribute111 parameter = parameter.replace('_', '-').upper()112 signature = "%s %s" % (signature, parameter)113 if self.is_list:114 signature = "%s [+]" % signature115 return signature116#117# Options used by ``htsql-ctl``.118#119HelpOption = Option(120 attribute='help',121 long_name='--help',122 hint="""describe the usage of the application""")123VersionOption = Option(124 attribute='version',125 long_name='--version',126 hint="""report the version of the application""")127QuietOption = Option(128 attribute='quiet',129 short_name='-q',130 long_name='--quiet',131 hint="""display as little as possible""")132VerboseOption = Option(133 attribute='verbose',134 short_name='-v',135 long_name='--verbose',136 hint="""display more information""")137DebugOption = Option(138 attribute='debug',139 long_name='--debug',140 hint="""enable debug logging""")141ForceOption = Option(142 attribute='force',143 long_name='--force',144 hint="""force execution of the routine""")145DryRunOption = Option(146 attribute='dry_run',147 long_name='--dry-run',148 hint="""simulate execution of the routine""")149HostOption = Option(150 attribute='host',151 long_name='--host',152 with_value=True,153 validator=StrVal(),154 default='',155 hint="""host to listen for incoming connections""")156PortOption = Option(157 attribute='port',158 long_name='--port',159 with_value=True,160 validator=UIntVal(65535),161 default=8080,162 hint="""port to listen for incoming connections""")163InputOption = Option(164 attribute='input',165 short_name='-i',166 long_name='--input',167 with_value=True,168 value_name="file",169 validator=StrVal(),170 hint="""set input file to FILE""")171OutputOption = Option(172 attribute='output',173 short_name='-o',174 long_name='--output',175 with_value=True,176 value_name="file",177 validator=StrVal(),178 hint="""set output file to FILE""")179PasswordOption = Option(180 attribute='password',181 short_name='-p',182 long_name='--password',183 hint="""ask for the database password""")184ExtensionsOption = Option(185 attribute='extensions',186 short_name='-E',187 long_name='--extension',188 with_value=True,189 value_name="ext",190 validator=ExtensionVal(),191 is_list=True,192 hint="""include extra extensions""")193ConfigOption = Option(194 attribute='config',195 short_name='-C',196 long_name='--config',197 with_value=True,198 value_name="file",199 validator=StrVal(),200 hint="""read HTSQL configuration from FILE""")201TrainOption = Option(202 attribute='train',203 long_name='--train',204 hint="""train the test engine""")205PurgeOption = Option(206 attribute='purge',207 long_name='--purge',208 hint="""purge unused data""")209SlaveOption = Option(210 attribute='slave',211 long_name='--slave',212 hint="""run in the slave mode""")213RemoteUserOption = Option(214 attribute='remote_user',215 long_name='--remote-user',216 with_value=True,217 value_name="user",218 validator=StrVal(),219 hint="""set the remote user to USER""")220WithHeadersOption = Option(221 attribute='with_headers',222 long_name='--with-headers',223 hint="""display HTTP status line and headers""")224ContentTypeOption = Option(225 attribute='content_type',226 long_name='--content-type',227 with_value=True,228 value_name='type',229 validator=StrVal(r"^[0-9a-z-]+/[0-9a-z-]+$"),...

Full Screen

Full Screen

test_publication_i18n.py

Source:test_publication_i18n.py Github

copy

Full Screen

...9@with_fixtures(10 "./eruditarticle/tests/fixtures/publication/volume_numbering", EruditPublication11)12class TestPublicationVolumeNumberingEnglish(object):13 @with_value("cd02305.xml", "get_volume_numbering", formatted=True)14 def test_can_format_volume_and_number_in_en(self, value):15 assert value == "Volume 56, Number 3-4, September–December 2015"16 @with_value("annuaire3703.xml", "get_volume_numbering", formatted=True)17 def test_can_format_volume_numbering_horsserie_year_in_en(self, value):18 assert value == "Special Issue, 2001"19 @with_value("haf2442.xml", "get_volume_numbering", formatted=True)20 def test_can_format_volume_numbering_in_case_of_index_in_en(self, value):21 assert value == "Index, 1997"22 @with_value("sequences1128840.xml", "get_volume_numbering", formatted=True)23 def test_can_format_volume_numbering_no_volume_multiple_months_in_en(self, value):24 assert value == "Number 211, January–February 2001"25 @with_value("sequences1081634.xml", "get_volume_numbering", formatted=True)26 def test_can_format_volume_numbering_in_case_of_index_with_number_in_en(27 self, value28 ):29 assert value == "Number 125, Index, 1986"30 @with_value("inter1068986.xml", "get_volume_numbering", formatted=True)31 def test_can_format_volume_numbering_in_case_of_supplement_in_en(self, value):32 assert value == "Number 110, Supplement, Winter 2012"33 @with_value("ehr1825418.xml", "get_volume_numbering", formatted=True)34 def test_can_format_volume_publication_period_in_en(self, value):35 assert value == "Volume 73, 2007"36 @with_value("crs1517600.xml", "get_volume_numbering", formatted=True)37 def test_can_format_volume_numbering_in_case_of_horsserie_in_en(self, value):38 assert value == "Special Issue, 2003"39 @with_value("va1503694.xml", "get_volume_numbering", formatted=True)40 def test_can_format_volume_number_numbertype_in_en(self, value):41 assert value == "Volume 52, Number 214, Supplement, Spring 2009"42 @with_value("as2866.xml", "get_volume_numbering", formatted=True)43 def test_can_format_volume_numbering_horsserie_no_number_in_en(self, value):...

Full Screen

Full Screen

min_variance.py

Source:min_variance.py Github

copy

Full Screen

1import numpy as np2import pandas as pd3import pandas.io.data as web4def create_portfolio(tickers, weights=None):5 if (weights is None):6 shares = np.ones(len(tickers))/len(tickers)7 portfolio = pd.DataFrame({'Tickers':tickers, 'Weights':weights},8 index=tickers)9 return portfolio10def calculate_weighted_portfolio_value(portfolio,returns,name='Value'):11 total_weights=portfolio.Weights.sum()12 weighted_returns = returns *(portfolio.Weights / total_weights)13 return pd.DataFrame({name: weighted_returns.sum(axis=1)})14def plot_portfolio_returns(returns,title=None):15 returns.plot(figsize=(12,8))16 plt.xlabel('Year')17 plt.ylabel('Returns')18 if (title is not None): plt.title(title)19 plt.show()20def get_historical_closes(ticker,start_date,end_date):21 p = web.DataReader(ticker,"yahoo",start_date,end_date)22 d = p.to_frame()['Adj Close'].reset_index()23 d.rename(columns={'minor': 'Ticker', 'Adj Close': 'Close'}, inplace=True)24 pivoted=d.pivot(index='Date',columns='Ticker')25 pivoted.columns = pivoted.columns.droplevel(0)26 return pivoted27def calc_daily_returns(closes):28 return np.log(closes/closes.shift(1))29def minvar(prices):30 cov=np.cov((prices[1:]/prices[:-1]-1).transpose())31 vu=np.array(cov.shape[1]*[1], float)32 num=np.dot(np.linalg.inv(cov),vu)33 den=np.dot(vu,num)34 return num/den35########### Enter in whatever stock you want36stocks=['SPY','TLT','EEM','GLD','MDY','VNQ','LQD']37closes = get_historical_closes(stocks,'2005-01-01','2015-09-30')38daily_returns = calc_daily_returns(closes)39weights = minvar(closes.values)40portfolio = create_portfolio(stocks,weights)41wr = calculate_weighted_portfolio_value(portfolio, daily_returns,name='Optimizor')42with_value = pd.concat([daily_returns, wr],axis=1)43with_value.cumsum().plot()44weights45df=with_value46df['6040']=with_value.SPY*.6+with_value.TLT*.447df.cumsum().plot()48sns.corrplot(df)49########### Now min var after 3 years of data50weights = minvar(closes[:dt(2009,1,1)].values)51portfolio = create_portfolio(stocks,weights)52wr = calculate_weighted_portfolio_value(portfolio, daily_returns)53with_value = pd.concat([daily_returns, wr],axis=1)54with_value.cumsum().plot()55weights56df=with_value57df['6040']=with_value.SPY*.6+with_value.TLT*.4...

Full Screen

Full Screen

generate_patterns.py

Source:generate_patterns.py Github

copy

Full Screen

1HASH_CHARS = '!@ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'2NUM_COLORS = 73def with_value(value=0.0, *, num_colors=7):4 return [[value for x in range(num_colors + 1)] for y in range(num_colors)]5def encode(m):6 def encode_row(row):7 return ''.join(HASH_CHARS[int((x + 0.25) * len(HASH_CHARS))] for x in row)8 return ''.join(encode_row(r) for r in m)9def likes_self(num_colors=NUM_COLORS):10 m = with_value(-0.1, num_colors=num_colors)11 for x in range(num_colors):12 m[x][0] = 0.213 m[x][x + 1] = 0.7414 return m15def red_kernels(num_colors=NUM_COLORS):16 m = with_value(-0.1, num_colors=num_colors)17 for x in range(num_colors):18 m[x][0] = 019 if x > 0:20 m[x][1] = 0.7421 return m22def neighbors(num_colors=NUM_COLORS):23 m = with_value(-0.1)24 for x in range(num_colors):25 m[x][0] = 026 m[x][x + 1] = -0.2527 x1 = 1 + (x + 1) % num_colors28 m[x][x1] = 0.529 return m30def middle(num_colors=NUM_COLORS):31 m = with_value(0.2)32 for x in range(num_colors):33 m[x][0] = -0.2534 m[x][x + 1] = 0.535 return m36def popular(num_colors=NUM_COLORS):37 m = with_value(0)38 for x in range(num_colors):39 m[x][0] = -0.140 f = x / (num_colors * 2)41 for y in range(num_colors):42 m[x][y + 1] = f43 if x == y:44 m[x][y + 1] += 0.245 return m46def circle(num_colors=3):47 m = with_value(-0.2, num_colors=num_colors)48 for x in range(num_colors):49 y = (x + 1) % num_colors50 m[x][0] = 0.151 m[x][y + 1] = 0.7452 return m53def no_love(num_colors=3):54 m = with_value(-0.2, num_colors=num_colors)55 for x in range(num_colors):56 m[x][0] = 0.057 return m58for fn, params in [59 (likes_self, 2),60 (likes_self, 5),61 (red_kernels, 5),62 (neighbors, None),63 (middle, None),64 (popular, None),65 (no_love, 5),66 (circle, 3),67 (circle, 4),68 (circle, 5)]:...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Sure automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful