Best Python code snippet using pytest-benchmark
test_timesince.py
Source:test_timesince.py
1# GNU MediaGoblin -- federated, autonomous media hosting2# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.3#4# This program is free software: you can redistribute it and/or modify5# it under the terms of the GNU Affero General Public License as published by6# the Free Software Foundation, either version 3 of the License, or7# (at your option) any later version.8#9# This program is distributed in the hope that it will be useful,10# but WITHOUT ANY WARRANTY; without even the implied warranty of11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12# GNU Affero General Public License for more details.13#14# You should have received a copy of the GNU Affero General Public License15# along with this program. If not, see <http://www.gnu.org/licenses/>.16from datetime import datetime, timedelta17from mediagoblin.tools.timesince import is_aware, timesince18def test_timesince():19 test_time = datetime.now()20 # it should ignore second and microseconds21 assert timesince(test_time, test_time + timedelta(microseconds=1)) == "0 minutes"22 assert timesince(test_time, test_time + timedelta(seconds=1)) == "0 minutes"23 # test minutes, hours, days, weeks, months and years (singular and plural)24 assert timesince(test_time, test_time + timedelta(minutes=1)) == "1 minute"25 assert timesince(test_time, test_time + timedelta(minutes=2)) == "2 minutes"26 assert timesince(test_time, test_time + timedelta(hours=1)) == "1 hour"27 assert timesince(test_time, test_time + timedelta(hours=2)) == "2 hours"28 assert timesince(test_time, test_time + timedelta(days=1)) == "1 day"29 assert timesince(test_time, test_time + timedelta(days=2)) == "2 days"30 assert timesince(test_time, test_time + timedelta(days=7)) == "1 week"31 assert timesince(test_time, test_time + timedelta(days=14)) == "2 weeks"32 assert timesince(test_time, test_time + timedelta(days=30)) == "1 month"33 assert timesince(test_time, test_time + timedelta(days=60)) == "2 months"34 assert timesince(test_time, test_time + timedelta(days=365)) == "1 year"35 assert timesince(test_time, test_time + timedelta(days=730)) == "2 years"36 # okay now we want to test combinations37 # e.g. 1 hour, 5 days38 assert timesince(test_time, test_time + timedelta(days=5, hours=1)) == "5 days, 1 hour"39 assert timesince(test_time, test_time + timedelta(days=15)) == "2 weeks, 1 day"40 assert timesince(test_time, test_time + timedelta(days=97)) == "3 months, 1 week"...
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!!