Best Python code snippet using lemoncheesecake
test_values_fetcher.py
Source:test_values_fetcher.py
...36def test__first_fetch(values_fetcher):37 ps = pd.Period('2014-1', freq='M')38 pe = pd.Period('2015-1', freq='M')39 values = values_fetcher._fetch(start_period=ps, end_period=pe)40 assert_that(values, has_length((pe - ps).n + 1))41 assert_that(values_fetcher._values_func.requests, has_length(1))42 assert min(values.date.dt.to_period(freq='M')) == ps43 assert max(values.date.dt.to_period(freq='M')) == pe44 np.testing.assert_equal(values.close.values,45 values_fetcher._values_func(start_period=ps, end_period=pe).close.values)46def test__repeated_fetch_within_known_range(values_fetcher):47 ps1 = pd.Period('2014-1', freq='M')48 pe1 = pd.Period('2015-1', freq='M')49 _ = values_fetcher._fetch(start_period=ps1, end_period=pe1)50 ps2 = pd.Period('2014-3', freq='M')51 pe2 = pd.Period('2014-9', freq='M')52 values2 = values_fetcher._fetch(start_period=ps2, end_period=pe2)53 assert_that(values_fetcher._values_func.requests, has_length(1))54 assert_that(values2, has_length((pe2 - ps2).n + 1))55 np.testing.assert_equal(values2.close.values,56 values_fetcher._values_func(start_period=ps2, end_period=pe2).close.values)57 assert values_fetcher._period_range.start == ps158 assert values_fetcher._period_range.end == pe159def test__fetch_before_begin_period_with_intersection(values_fetcher):60 ps1 = pd.Period('2014-1', freq='M')61 pe1 = pd.Period('2015-1', freq='M')62 _ = values_fetcher._fetch(start_period=ps1, end_period=pe1)63 ps2 = pd.Period('2013-9', freq='M')64 pe2 = pd.Period('2014-3', freq='M')65 values2 = values_fetcher._fetch(start_period=ps2, end_period=pe2)66 assert_that(values_fetcher._values_func.requests, has_length(2))67 assert_that(values2, has_length((pe2 - ps2).n + 1))68 np.testing.assert_equal(values2.close.values,69 values_fetcher._values_func(start_period=ps2, end_period=pe2).close.values)70 assert values_fetcher._period_range.start == ps271 assert values_fetcher._period_range.end == pe172def test__fetch_before_begin_period_with_separate_regions(values_fetcher):73 ps1 = pd.Period('2014-1', freq='M')74 pe1 = pd.Period('2015-1', freq='M')75 _ = values_fetcher._fetch(start_period=ps1, end_period=pe1)76 ps2 = pd.Period('2013-1', freq='M')77 pe2 = pd.Period('2013-6', freq='M')78 values2 = values_fetcher._fetch(start_period=ps2, end_period=pe2)79 assert_that(values_fetcher._values_func.requests, has_length(2))80 assert_that(values2, has_length((pe2 - ps2).n + 1))81 np.testing.assert_equal(values2.close.values,82 values_fetcher._values_func(start_period=ps2, end_period=pe2).close.values)83 assert values_fetcher._period_range.start == ps284 assert values_fetcher._period_range.end == pe185def test__fetch_after_end_period_with_intersection(values_fetcher):86 ps1 = pd.Period('2014-1', freq='M')87 pe1 = pd.Period('2015-1', freq='M')88 _ = values_fetcher._fetch(start_period=ps1, end_period=pe1)89 ps2 = pd.Period('2014-6', freq='M')90 pe2 = pd.Period('2015-6', freq='M')91 values2 = values_fetcher._fetch(start_period=ps2, end_period=pe2)92 assert_that(values_fetcher._values_func.requests, has_length(2))93 assert_that(values2, has_length((pe2 - ps2).n + 1))94 np.testing.assert_equal(values2.close.values,95 values_fetcher._values_func(start_period=ps2, end_period=pe2).close.values)96 assert values_fetcher._period_range.start == ps197 assert values_fetcher._period_range.end == pe298def test__fetch_before_end_period_with_separate_regions(values_fetcher):99 ps1 = pd.Period('2014-1', freq='M')100 pe1 = pd.Period('2015-1', freq='M')101 _ = values_fetcher._fetch(start_period=ps1, end_period=pe1)102 ps2 = pd.Period('2015-6', freq='M')103 pe2 = pd.Period('2016-1', freq='M')104 values2 = values_fetcher._fetch(start_period=ps2, end_period=pe2)105 assert_that(values_fetcher._values_func.requests, has_length(2))106 assert_that(values2, has_length((pe2 - ps2).n + 1))107 np.testing.assert_equal(values2.close.values,108 values_fetcher._values_func(start_period=ps2, end_period=pe2).close.values)109 assert values_fetcher._period_range.start == ps1110 assert values_fetcher._period_range.end == pe2111def test__fetch_broader_than_stored_region(values_fetcher):112 ps1 = pd.Period('2014-1', freq='M')113 pe1 = pd.Period('2015-1', freq='M')114 _ = values_fetcher._fetch(start_period=ps1, end_period=pe1)115 ps2 = pd.Period('2013-6', freq='M')116 pe2 = pd.Period('2016-6', freq='M')117 values2 = values_fetcher._fetch(start_period=ps2, end_period=pe2)118 assert_that(values_fetcher._values_func.requests, has_length(2))119 assert_that(values2, has_length((pe2 - ps2).n + 1))120 np.testing.assert_equal(values2.close.values,121 values_fetcher._values_func(start_period=ps2, end_period=pe2).close.values)122 assert values_fetcher._period_range.start == ps2...
haslength_test.py
Source:haslength_test.py
...21 def __str__(self):22 return "FakeWithoutLen"23class HasLengthTest(MatcherTest):24 def testPassesResultOfLenToNestedMatcher(self):25 self.assert_matches("equal", has_length(equal_to(42)), FakeWithLen(42))26 self.assert_does_not_match("unequal", has_length(equal_to(42)), FakeWithLen(1))27 def testProvidesConvenientShortcutForHasLengthEqualTo(self):28 self.assert_matches("equal", has_length(42), FakeWithLen(42))29 self.assert_does_not_match("unequal", has_length(42), FakeWithLen(1))30 def testDoesNotMatchObjectWithoutLen(self):31 self.assert_does_not_match("no length", has_length(42), object())32 def testHasReadableDescription(self):33 self.assert_description(34 "an object with length of a value greater than <5>", has_length(greater_than(5))35 )36 def testSuccessfulMatchDoesNotGenerateMismatchDescription(self):37 self.assert_no_mismatch_description(has_length(3), "foo")38 def testMismatchDescriptionForItemWithWrongLength(self):39 self.assert_mismatch_description(40 "was <FakeWithLen> with length of <4>", has_length(3), FakeWithLen(4)41 )42 def testMismatchDescriptionForItemWithoutLength(self):43 self.assert_mismatch_description("was <FakeWithoutLen>", has_length(3), FakeWithoutLen())44 def testDescribeMismatchForItemWithWrongLength(self):45 self.assert_describe_mismatch(46 "was <FakeWithLen> with length of <4>", has_length(3), FakeWithLen(4)47 )48 def testDescribeMismatchForItemWithoutLength(self):49 self.assert_describe_mismatch("was <FakeWithoutLen>", has_length(3), FakeWithoutLen())50if __name__ == "__main__":...
day8.py
Source:day8.py
...5 if filter_func(value):6 values.remove(value)7 return value89def has_length(x):10 def checker(code):11 return len(code) == x12 return checker1314def missing(known, num):15 def checker(code):16 return len(known.difference(code)) == num17 return checker1819def both(a, b):20 return lambda x: a(x) and b(x)2122def solve(input, output):23 key = {}24 unknowns = list(map(set, input.split()))25 key[1] = matches(has_length(2), unknowns)26 key[7] = matches(has_length(3), unknowns)27 key[4] = matches(has_length(4), unknowns)28 key[8] = matches(has_length(7), unknowns)29 key[6] = matches(both(has_length(6), missing(key[1], 1)), unknowns)30 key[0] = matches(both(has_length(6), missing(key[4], 1)), unknowns)31 key[9] = matches(has_length(6), unknowns)32 key[3] = matches(both(has_length(5), missing(key[1], 0)), unknowns)33 key[5] = matches(both(has_length(5), missing(key[6], 1)), unknowns)34 key[2] = matches(has_length(5), unknowns)3536 assert len(unknowns) == 03738 result = 039 for digit in map(set, output.split()):40 for outval, inval in key.items():41 if digit == inval:42 result = result * 10 + outval43 return result4445# five char digits: 2, 3, 546# six char digits: 0, 6, 947# a = 7 - 148# 6 = missing one of the chars in 1
...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!