How to use _truncate method in Slash

Best Python code snippet using slash

date_ranges.py

Source:date_ranges.py Github

copy

Full Screen

1from datetime import timedelta2from django.db.models import Q3from django.utils.timezone import now4def _truncate(dt):5 return dt.date()6date_ranges = {7 "today": {8 "label": "Today",9 "filter": lambda qs, name: qs.filter(10 **{11 "%s__year" % name: now().year,12 "%s__month" % name: now().month,13 "%s__day" % name: now().day,14 }15 ),16 "Q": lambda name: Q(17 **{18 "%s__year" % name: now().year,19 "%s__month" % name: now().month,20 "%s__day" % name: now().day,21 }22 ),23 "dayrange": lambda: [_truncate(now())],24 },25 "yesterday": {26 "label": "Yesterday",27 "filter": lambda qs, name: qs.filter(28 **{29 "%s__year" % name: (now() - timedelta(days=1)).year,30 "%s__month" % name: (now() - timedelta(days=1)).month,31 "%s__day" % name: (now() - timedelta(days=1)).day,32 }33 ),34 "Q": lambda name: Q(35 **{36 "%s__year" % name: (now() - timedelta(days=1)).year,37 "%s__month" % name: (now() - timedelta(days=1)).month,38 "%s__day" % name: (now() - timedelta(days=1)).day,39 }40 ),41 "dayrange": lambda: [_truncate(now() - timedelta(days=1))],42 },43 "week": {44 "label": "Last 7 days",45 "filter": lambda qs, name: qs.filter(46 **{47 "%s__gte" % name: _truncate(now() - timedelta(days=6)),48 "%s__lt" % name: _truncate(now() + timedelta(days=1)),49 }50 ),51 "Q": lambda name: Q(52 **{53 "%s__gte" % name: _truncate(now() - timedelta(days=6)),54 "%s__lt" % name: _truncate(now() + timedelta(days=1)),55 }56 ),57 "dayrange": lambda: (58 _truncate(now() - timedelta(days=(6 - x))) for x in range(7)59 ),60 },61 "month": {62 "label": "Last 30 days",63 "filter": lambda qs, name: qs.filter(64 **{65 "%s__gte" % name: _truncate(now() - timedelta(days=29)),66 "%s__lt" % name: _truncate(now() + timedelta(days=1)),67 }68 ),69 "Q": lambda name: Q(70 **{71 "%s__gte" % name: _truncate(now() - timedelta(days=29)),72 "%s__lt" % name: _truncate(now() + timedelta(days=1)),73 }74 ),75 "dayrange": lambda: (76 _truncate(now() - timedelta(days=(29 - x))) for x in range(30)77 ),78 },79 "quarter": {80 "label": "Last 90 days",81 "filter": lambda qs, name: qs.filter(82 **{83 "%s__gte" % name: _truncate(now() - timedelta(days=89)),84 "%s__lt" % name: _truncate(now() + timedelta(days=1)),85 }86 ),87 "Q": lambda name: Q(88 **{89 "%s__gte" % name: _truncate(now() - timedelta(days=89)),90 "%s__lt" % name: _truncate(now() + timedelta(days=1)),91 }92 ),93 "dayrange": lambda: (94 _truncate(now() - timedelta(days=(89 - x))) for x in range(90)95 ),96 },97 "year": {98 "label": "Last 12 months",99 "filter": lambda qs, name: qs.filter(100 **{101 "%s__gte" % name: _truncate(now() - timedelta(days=364)),102 "%s__lt" % name: _truncate(now() + timedelta(days=1)),103 }104 ),105 "Q": lambda name: Q(106 **{107 "%s__gte" % name: _truncate(now() - timedelta(days=364)),108 "%s__lt" % name: _truncate(now() + timedelta(days=1)),109 }110 ),111 "dayrange": lambda: (112 _truncate(now() - timedelta(days=(364 - x))) for x in range(365)113 ),114 },...

Full Screen

Full Screen

test_exercise5.py

Source:test_exercise5.py Github

copy

Full Screen

...6# Arrange7# Act8 value = Decimal(0.00*0.95)9# Assert10 assert calculate_price(Decimal(0.00), date(2022,4,9)) == _truncate(value)11def test_valid2():12# Arrange13# Act14 value = Decimal(50.00*0.95)15# Assert16 assert calculate_price(Decimal(50.00), date(2022,4,18)) == _truncate(value)17def test_valid3():18# Arrange19# Act20 value = Decimal(50.01*0.90)21# Assert22 assert calculate_price(Decimal(50.01), date(2022,4,10)) == _truncate(value)23def test_valid4():24# Arrange25# Act26 value = Decimal(100.00*0.90)27# Assert28 assert calculate_price(Decimal(100.00), date(2022,4,17)) == _truncate(value)29def test_valid5():30# Arrange31# Act32 value = Decimal(85.01)33# Assert34 assert calculate_price(Decimal(100.01), date(2022,4,18)) == _truncate(value)35def test_valid6():36# Arrange37# Act38 value = Decimal(100.02*0.85)39# Assert40 assert calculate_price(Decimal(100.02), date(2022,4,10)) == _truncate(value)41def test_valid7():42# Arrange43# Act44 value = Decimal(200.00*1.00)45# Assert46 assert calculate_price(Decimal(200.00), date(2022,4,8)) == _truncate(value)47def test_valid8():48# Arrange49# Act50 value = Decimal(49.99*1.00)51# Assert52 assert calculate_price(Decimal(49.99), date(2022,4,19)) == _truncate(value)53def test_valid9():54# Arrange55# Act56 value = Decimal(850.00*0.85)57# Assert58 assert calculate_price(Decimal(850.00), date(2022,4,17)) == _truncate(value)59def test_valid10():60# Arrange61# Act62 value = Decimal(1000.00*0.85)63# Assert64 assert calculate_price(Decimal(1000.00), date(2022,4,16)) == _truncate(value)65# -------------------------------------------------------------------------------66def test_invalid11():67# Arrange68# Act69 with pytest.raises(ValueError) as error_message:70 calculate_price(Decimal(-0.01), date(2022, 4, 9))71# Assert72 assert error_message.type == ValueError73def test_invalid12():74# Arrange75# Act76 with pytest.raises(ValueError) as error_message:77 calculate_price(Decimal(0.00), "a")78# Assert...

Full Screen

Full Screen

plottools.py

Source:plottools.py Github

copy

Full Screen

...5 return self._maxLen6 def __init__(self, *args, **kwargs):7 self._maxLen = kwargs.pop("maxLen")8 list.__init__(self, *args, **kwargs)9 def _truncate(self):10 """Called by various methods to reinforce the maximum length."""11 dif = len(self)-self._maxLen12 if dif > 0:13 self[:dif]=[]14 def append(self, x):15 list.append(self, x)16 self._truncate()17 def insert(self, *args):18 list.insert(self, *args)19 self._truncate()20 def extend(self, x):21 list.extend(self, x)22 self._truncate()23 def __setitem__(self, *args):24 list.__setitem__(self, *args)25 self._truncate()26 def __setslice__(self, *args):27 list.__setslice__(self, *args)...

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 Slash 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