How to use _format_token method in Gherkin-python

Best Python code snippet using gherkin-python

test_formatter.py

Source:test_formatter.py Github

copy

Full Screen

...22 result = self.formatter.format(dt, "MM-DD-YYYY hh:mm:ss a")23 assert result == "02-05-2013 12:32:51 pm"24 def test_year(self):25 dt = datetime(2013, 1, 1)26 assert self.formatter._format_token(dt, "YYYY") == "2013"27 assert self.formatter._format_token(dt, "YY") == "13"28 def test_month(self):29 dt = datetime(2013, 1, 1)30 assert self.formatter._format_token(dt, "MMMM") == "January"31 assert self.formatter._format_token(dt, "MMM") == "Jan"32 assert self.formatter._format_token(dt, "MM") == "01"33 assert self.formatter._format_token(dt, "M") == "1"34 def test_day(self):35 dt = datetime(2013, 2, 1)36 assert self.formatter._format_token(dt, "DDDD") == "032"37 assert self.formatter._format_token(dt, "DDD") == "32"38 assert self.formatter._format_token(dt, "DD") == "01"39 assert self.formatter._format_token(dt, "D") == "1"40 assert self.formatter._format_token(dt, "Do") == "1st"41 assert self.formatter._format_token(dt, "dddd") == "Friday"42 assert self.formatter._format_token(dt, "ddd") == "Fri"43 assert self.formatter._format_token(dt, "d") == "5"44 def test_hour(self):45 dt = datetime(2013, 1, 1, 2)46 assert self.formatter._format_token(dt, "HH") == "02"47 assert self.formatter._format_token(dt, "H") == "2"48 dt = datetime(2013, 1, 1, 13)49 assert self.formatter._format_token(dt, "HH") == "13"50 assert self.formatter._format_token(dt, "H") == "13"51 dt = datetime(2013, 1, 1, 2)52 assert self.formatter._format_token(dt, "hh") == "02"53 assert self.formatter._format_token(dt, "h") == "2"54 dt = datetime(2013, 1, 1, 13)55 assert self.formatter._format_token(dt, "hh") == "01"56 assert self.formatter._format_token(dt, "h") == "1"57 # test that 12-hour time converts to '12' at midnight58 dt = datetime(2013, 1, 1, 0)59 assert self.formatter._format_token(dt, "hh") == "12"60 assert self.formatter._format_token(dt, "h") == "12"61 def test_minute(self):62 dt = datetime(2013, 1, 1, 0, 1)63 assert self.formatter._format_token(dt, "mm") == "01"64 assert self.formatter._format_token(dt, "m") == "1"65 def test_second(self):66 dt = datetime(2013, 1, 1, 0, 0, 1)67 assert self.formatter._format_token(dt, "ss") == "01"68 assert self.formatter._format_token(dt, "s") == "1"69 def test_sub_second(self):70 dt = datetime(2013, 1, 1, 0, 0, 0, 123456)71 assert self.formatter._format_token(dt, "SSSSSS") == "123456"72 assert self.formatter._format_token(dt, "SSSSS") == "12345"73 assert self.formatter._format_token(dt, "SSSS") == "1234"74 assert self.formatter._format_token(dt, "SSS") == "123"75 assert self.formatter._format_token(dt, "SS") == "12"76 assert self.formatter._format_token(dt, "S") == "1"77 dt = datetime(2013, 1, 1, 0, 0, 0, 2000)78 assert self.formatter._format_token(dt, "SSSSSS") == "002000"79 assert self.formatter._format_token(dt, "SSSSS") == "00200"80 assert self.formatter._format_token(dt, "SSSS") == "0020"81 assert self.formatter._format_token(dt, "SSS") == "002"82 assert self.formatter._format_token(dt, "SS") == "00"83 assert self.formatter._format_token(dt, "S") == "0"84 def test_timestamp(self):85 dt = datetime.now(tz=dateutil_tz.UTC)86 expected = str(dt.timestamp())87 assert self.formatter._format_token(dt, "X") == expected88 # Must round because time.time() may return a float with greater89 # than 6 digits of precision90 expected = str(int(dt.timestamp() * 1000000))91 assert self.formatter._format_token(dt, "x") == expected92 def test_timezone(self):93 dt = datetime.utcnow().replace(tzinfo=dateutil_tz.gettz("US/Pacific"))94 result = self.formatter._format_token(dt, "ZZ")95 assert result == "-07:00" or result == "-08:00"96 result = self.formatter._format_token(dt, "Z")97 assert result == "-0700" or result == "-0800"98 @pytest.mark.parametrize("full_tz_name", make_full_tz_list())99 def test_timezone_formatter(self, full_tz_name):100 # This test will fail if we use "now" as date as soon as we change from/to DST101 dt = datetime(1986, 2, 14, tzinfo=pytz.timezone("UTC")).replace(102 tzinfo=dateutil_tz.gettz(full_tz_name)103 )104 abbreviation = dt.tzname()105 result = self.formatter._format_token(dt, "ZZZ")106 assert result == abbreviation107 def test_am_pm(self):108 dt = datetime(2012, 1, 1, 11)109 assert self.formatter._format_token(dt, "a") == "am"110 assert self.formatter._format_token(dt, "A") == "AM"111 dt = datetime(2012, 1, 1, 13)112 assert self.formatter._format_token(dt, "a") == "pm"113 assert self.formatter._format_token(dt, "A") == "PM"114 def test_week(self):115 dt = datetime(2017, 5, 19)116 assert self.formatter._format_token(dt, "W") == "2017-W20-5"117 # make sure week is zero padded when needed118 dt_early = datetime(2011, 1, 20)119 assert self.formatter._format_token(dt_early, "W") == "2011-W03-4"120 def test_nonsense(self):121 dt = datetime(2012, 1, 1, 11)122 assert self.formatter._format_token(dt, None) is None123 assert self.formatter._format_token(dt, "NONSENSE") is None124 def test_escape(self):125 assert (126 self.formatter.format(127 datetime(2015, 12, 10, 17, 9), "MMMM D, YYYY [at] h:mma"128 )129 == "December 10, 2015 at 5:09pm"130 )131 assert (132 self.formatter.format(133 datetime(2015, 12, 10, 17, 9), "[MMMM] M D, YYYY [at] h:mma"134 )135 == "MMMM 12 10, 2015 at 5:09pm"136 )137 assert (...

Full Screen

Full Screen

formatter.py

Source:formatter.py Github

copy

Full Screen

...28 locale: locales.Locale29 def __init__(self, locale: str = "en_us") -> None:30 self.locale = locales.get_locale(locale)31 def format(cls, dt: datetime, fmt: str) -> str:32 # FIXME: _format_token() is nullable33 return cls._FORMAT_RE.sub(34 lambda m: cast(str, cls._format_token(dt, m.group(0))), fmt35 )36 def _format_token(self, dt: datetime, token: Optional[str]) -> Optional[str]:37 if token and token.startswith("[") and token.endswith("]"):38 return token[1:-1]39 if token == "YYYY":40 return self.locale.year_full(dt.year)41 if token == "YY":42 return self.locale.year_abbreviation(dt.year)43 if token == "MMMM":44 return self.locale.month_name(dt.month)45 if token == "MMM":46 return self.locale.month_abbreviation(dt.month)47 if token == "MM":48 return f"{dt.month:02d}"49 if token == "M":50 return f"{dt.month}"...

Full Screen

Full Screen

formatter_tests.py

Source:formatter_tests.py Github

copy

Full Screen

...12 result = self.formatter.format(dt, 'MM-DD-YYYY hh:mm:ss a')13 assertEqual(result, '02-05-2013 12:32:51 pm')14 def test_year(self):15 dt = datetime(2013, 1, 1)16 assertEqual(self.formatter._format_token(dt, 'YYYY'), '2013')17 assertEqual(self.formatter._format_token(dt, 'YY'), '13')18 def test_month(self):19 dt = datetime(2013, 1, 1)20 assertEqual(self.formatter._format_token(dt, 'MMMM'), 'January')21 assertEqual(self.formatter._format_token(dt, 'MMM'), 'Jan')22 assertEqual(self.formatter._format_token(dt, 'MM'), '01')23 assertEqual(self.formatter._format_token(dt, 'M'), '1')24 def test_day(self):25 dt = datetime(2013, 2, 1)26 assertEqual(self.formatter._format_token(dt, 'DDDD'), '032')27 assertEqual(self.formatter._format_token(dt, 'DDD'), '32')28 assertEqual(self.formatter._format_token(dt, 'DD'), '01')29 assertEqual(self.formatter._format_token(dt, 'D'), '1')30 assertEqual(self.formatter._format_token(dt, 'Do'), '1st')31 assertEqual(self.formatter._format_token(dt, 'dddd'), 'Friday')32 assertEqual(self.formatter._format_token(dt, 'ddd'), 'Fri')33 assertEqual(self.formatter._format_token(dt, 'd'), '5')34 def test_hour(self):35 dt = datetime(2013, 1, 1, 2)36 assertEqual(self.formatter._format_token(dt, 'HH'), '02')37 assertEqual(self.formatter._format_token(dt, 'H'), '2')38 dt = datetime(2013, 1, 1, 13)39 assertEqual(self.formatter._format_token(dt, 'HH'), '13')40 assertEqual(self.formatter._format_token(dt, 'H'), '13')41 dt = datetime(2013, 1, 1, 2)42 assertEqual(self.formatter._format_token(dt, 'hh'), '02')43 assertEqual(self.formatter._format_token(dt, 'h'), '2')44 dt = datetime(2013, 1, 1, 13)45 assertEqual(self.formatter._format_token(dt, 'hh'), '01')46 assertEqual(self.formatter._format_token(dt, 'h'), '1')47 # test that 12-hour time converts to '12' at midnight48 dt = datetime(2013, 1, 1, 0)49 assertEqual(self.formatter._format_token(dt, 'hh'), '12')50 assertEqual(self.formatter._format_token(dt, 'h'), '12')51 def test_minute(self):52 dt = datetime(2013, 1, 1, 0, 1)53 assertEqual(self.formatter._format_token(dt, 'mm'), '01')54 assertEqual(self.formatter._format_token(dt, 'm'), '1')55 def test_second(self):56 dt = datetime(2013, 1, 1, 0, 0, 1)57 assertEqual(self.formatter._format_token(dt, 'ss'), '01')58 assertEqual(self.formatter._format_token(dt, 's'), '1')59 def test_sub_second(self):60 dt = datetime(2013, 1, 1, 0, 0, 0, 123456)61 assertEqual(self.formatter._format_token(dt, 'SSSSSS'), '123456')62 assertEqual(self.formatter._format_token(dt, 'SSSSS'), '12345')63 assertEqual(self.formatter._format_token(dt, 'SSSS'), '1234')64 assertEqual(self.formatter._format_token(dt, 'SSS'), '123')65 assertEqual(self.formatter._format_token(dt, 'SS'), '12')66 assertEqual(self.formatter._format_token(dt, 'S'), '1')67 dt = datetime(2013, 1, 1, 0, 0, 0, 2000)68 assertEqual(self.formatter._format_token(dt, 'SSSSSS'), '002000')69 assertEqual(self.formatter._format_token(dt, 'SSSSS'), '00200')70 assertEqual(self.formatter._format_token(dt, 'SSSS'), '0020')71 assertEqual(self.formatter._format_token(dt, 'SSS'), '002')72 assertEqual(self.formatter._format_token(dt, 'SS'), '00')73 assertEqual(self.formatter._format_token(dt, 'S'), '0')74 def test_timestamp(self):75 timestamp = time.time()76 dt = datetime.utcfromtimestamp(timestamp)77 assertEqual(self.formatter._format_token(dt, 'X'), str(int(timestamp)))78 def test_timezone(self):79 dt = datetime.utcnow().replace(tzinfo=dateutil_tz.gettz('US/Pacific'))80 result = self.formatter._format_token(dt, 'ZZ')81 assertTrue(result == '-07:00' or result == '-08:00')82 result = self.formatter._format_token(dt, 'Z')83 assertTrue(result == '-0700' or result == '-0800')84 def test_am_pm(self):85 dt = datetime(2012, 1, 1, 11)86 assertEqual(self.formatter._format_token(dt, 'a'), 'am')87 assertEqual(self.formatter._format_token(dt, 'A'), 'AM')88 dt = datetime(2012, 1, 1, 13)89 assertEqual(self.formatter._format_token(dt, 'a'), 'pm')90 assertEqual(self.formatter._format_token(dt, 'A'), 'PM')91 def test_nonsense(self):92 dt = datetime(2012, 1, 1, 11)93 assertEqual(self.formatter._format_token(dt, None), None)...

Full Screen

Full Screen

token_formatter_builder.py

Source:token_formatter_builder.py Github

copy

Full Screen

...10 pass11 def end_rule(self, rule_type):12 pass13 def get_result(self):14 return '\n'.join([self._format_token(token) for token in self._tokens])15 def _format_token(self, token):16 if token.eof():17 return "EOF"18 return ''.join([19 '(',20 str(token.location['line']), ':', str(token.location['column']),21 ')',22 token.matched_type,23 ':',24 (token.matched_keyword if token.matched_keyword else ''),25 '/',26 (token.matched_text if token.matched_text else ""),27 '/',28 ','.join([str(item['column']) + ':' + item['text'] for item in token.matched_items])29 ])

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 Gherkin-python 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