summaryrefslogtreecommitdiffstatshomepage
path: root/tests
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-08-24 17:40:24 +0100
committerDamien George <damien.p.george@gmail.com>2014-08-24 17:40:24 +0100
commit8ba832456e2e14db915e548a8ac3c6d4017c901e (patch)
tree1772c115166d2b17381aba61a8c400c7582ab188 /tests
parent6678595e7ed9e36c4aa1460f0af87119bd880240 (diff)
downloadmicropython-8ba832456e2e14db915e548a8ac3c6d4017c901e.tar.gz
micropython-8ba832456e2e14db915e548a8ac3c6d4017c901e.zip
stmhal, modtime: Small changes, reduced code size by around 80 bytes.
Also added test for modtime.
Diffstat (limited to 'tests')
-rw-r--r--tests/pyb/modtime.py38
-rw-r--r--tests/pyb/modtime.py.exp34
2 files changed, 72 insertions, 0 deletions
diff --git a/tests/pyb/modtime.py b/tests/pyb/modtime.py
new file mode 100644
index 0000000000..de6f8fbc6b
--- /dev/null
+++ b/tests/pyb/modtime.py
@@ -0,0 +1,38 @@
+import time
+
+DAYS_PER_MONTH = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
+
+def is_leap(year):
+ return (year % 4) == 0
+
+def test():
+ seconds = 0
+ wday = 5 # Jan 1, 2000 was a Saturday
+ for year in range(2000, 2034):
+ print("Testing %d" % year)
+ yday = 1
+ for month in range(1, 13):
+ if month == 2 and is_leap(year):
+ DAYS_PER_MONTH[2] = 29
+ else:
+ DAYS_PER_MONTH[2] = 28
+ for day in range(1, DAYS_PER_MONTH[month] + 1):
+ secs = time.mktime((year, month, day, 0, 0, 0, 0, 0))
+ if secs != seconds:
+ print("mktime failed for %d-%02d-%02d got %d expected %d" % (year, month, day, secs, seconds))
+ tuple = time.localtime(seconds)
+ secs = time.mktime(tuple)
+ if secs != seconds:
+ print("localtime failed for %d-%02d-%02d got %d expected %d" % (year, month, day, secs, seconds))
+ return
+ seconds += 86400
+ if yday != tuple[7]:
+ print("locatime for %d-%02d-%02d got yday %d, expecting %d" % (year, month, day, tuple[7], yday))
+ return
+ if wday != tuple[6]:
+ print("locatime for %d-%02d-%02d got wday %d, expecting %d" % (year, month, day, tuple[6], wday))
+ return
+ yday += 1
+ wday = (wday + 1) % 7
+
+test()
diff --git a/tests/pyb/modtime.py.exp b/tests/pyb/modtime.py.exp
new file mode 100644
index 0000000000..0bf7c43f98
--- /dev/null
+++ b/tests/pyb/modtime.py.exp
@@ -0,0 +1,34 @@
+Testing 2000
+Testing 2001
+Testing 2002
+Testing 2003
+Testing 2004
+Testing 2005
+Testing 2006
+Testing 2007
+Testing 2008
+Testing 2009
+Testing 2010
+Testing 2011
+Testing 2012
+Testing 2013
+Testing 2014
+Testing 2015
+Testing 2016
+Testing 2017
+Testing 2018
+Testing 2019
+Testing 2020
+Testing 2021
+Testing 2022
+Testing 2023
+Testing 2024
+Testing 2025
+Testing 2026
+Testing 2027
+Testing 2028
+Testing 2029
+Testing 2030
+Testing 2031
+Testing 2032
+Testing 2033