From a926acf9f6197288779334d04d20acd94b1fd0fe Mon Sep 17 00:00:00 2001 From: Joachim Metz Date: Wed, 13 May 2026 17:18:27 +0200 Subject: [PATCH 1/2] Worked on tests --- MANIFEST.in | 2 +- config/dpkg/changelog | 4 ++-- dfdatetime/__init__.py | 2 +- dfdatetime/serializer.py | 3 +++ pyproject.toml | 2 +- tests/apfs_time.py | 5 +++++ tests/decorators.py | 44 ++++++++++++++++++++++++++++++++++++++ tests/dotnet_datetime.py | 13 +++++++++++ tests/factory.py | 3 +++ tests/golang_time.py | 11 ++++++++++ tests/rfc2579_date_time.py | 4 ++++ tests/serializer.py | 26 ++++++++++++++++++++++ 12 files changed, 114 insertions(+), 5 deletions(-) create mode 100644 tests/decorators.py diff --git a/MANIFEST.in b/MANIFEST.in index 3447ab6..c5757cf 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -5,6 +5,6 @@ exclude .gitignore exclude *.pyc recursive-include config * recursive-exclude dfdatetime *.pyc -# The test scripts are not required in a binary distribution package they +# The test scripts are not required in a binary distribution package they # are considered source distribution files and excluded by find_package(). recursive-include tests *.py diff --git a/config/dpkg/changelog b/config/dpkg/changelog index 1176894..6b8327d 100644 --- a/config/dpkg/changelog +++ b/config/dpkg/changelog @@ -1,5 +1,5 @@ -dfdatetime (20260507-1) unstable; urgency=low +dfdatetime (20260513-1) unstable; urgency=low * Auto-generated - -- Log2Timeline maintainers Thu, 07 May 2026 05:21:30 +0200 + -- Log2Timeline maintainers Wed, 13 May 2026 17:16:59 +0200 diff --git a/dfdatetime/__init__.py b/dfdatetime/__init__.py index 9195fc6..af2fd9a 100644 --- a/dfdatetime/__init__.py +++ b/dfdatetime/__init__.py @@ -24,4 +24,4 @@ from dfdatetime import webkit_time -__version__ = '20260507' +__version__ = '20260513' diff --git a/dfdatetime/serializer.py b/dfdatetime/serializer.py index 5ff72cb..3950016 100644 --- a/dfdatetime/serializer.py +++ b/dfdatetime/serializer.py @@ -182,6 +182,9 @@ def ConvertJSONToDateTimeValues(cls, json_dict): Returns: dfdatetime.DateTimeValues: date and time values. + + Raises: + KeyError: If date and time values type is not supported by factory. """ class_name = json_dict.get('__class_name__') if class_name: diff --git a/pyproject.toml b/pyproject.toml index a0c458f..59e6a3f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "dfdatetime" -version = "20260507" +version = "20260513" description = "Digital Forensics date and time (dfDateTime)" maintainers = [ { name = "Log2Timeline maintainers", email = "log2timeline-maintainers@googlegroups.com" }, diff --git a/tests/apfs_time.py b/tests/apfs_time.py index 174c644..76e1191 100644 --- a/tests/apfs_time.py +++ b/tests/apfs_time.py @@ -52,6 +52,11 @@ def testCopyFromDateTimeString(self): def testCopyToDateTimeString(self): """Tests the CopyToDateTimeString function.""" + apfs_time_object = apfs_time.APFSTime(timestamp=1281643591987654321) + + date_time_string = apfs_time_object.CopyToDateTimeString() + self.assertEqual(date_time_string, '2010-08-12 20:06:31.987654321') + apfs_time_object = apfs_time.APFSTime(timestamp=9223372036854775810) date_time_string = apfs_time_object.CopyToDateTimeString() diff --git a/tests/decorators.py b/tests/decorators.py new file mode 100644 index 0000000..6f9dc57 --- /dev/null +++ b/tests/decorators.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python3 +"""Tests for the decorators.""" + +import unittest +import warnings + +from dfdatetime import decorators + + +class TestClass(object): + """Class for testing deprecated decorator.""" + + def Method(self): + """Test method.""" + return 'result' + + @decorators.deprecated + def DeprecatedMethod(self): + """Deprecated test method.""" + return 'deprecated_result' + + +class DeprecatedTest(unittest.TestCase): + """Tests for the deprecated decorator.""" + + def test_deprecated(self): + """Tests the deprecated decorator.""" + test_object = TestClass() + + result = test_object.Method() + self.assertEqual(result, 'result') + + with warnings.catch_warnings(record=True) as warning: + warnings.simplefilter('always', DeprecationWarning) + + result = test_object.DeprecatedMethod() + + self.assertEqual(result, 'deprecated_result') + self.assertEqual(len(warning), 1) + self.assertIn('DeprecatedMethod', str(warning[0].message)) + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/dotnet_datetime.py b/tests/dotnet_datetime.py index b702e70..f6a4613 100644 --- a/tests/dotnet_datetime.py +++ b/tests/dotnet_datetime.py @@ -93,6 +93,19 @@ def testCopyToDateTimeString(self): dotnet_date_string = dotnet_date_time.CopyToDateTimeString() self.assertEqual(dotnet_date_string, '2020-12-12 12:12:12.1230000') + # Test out of range timestamp + dotnet_date_time = dotnet_datetime.DotNetDateTime(timestamp=-1) + self.assertIsNone(dotnet_date_time.CopyToDateTimeString()) + + dotnet_date_time = dotnet_datetime.DotNetDateTime( + timestamp=dotnet_datetime.DotNetDateTime._UINT64_MAX + 1) + self.assertIsNone(dotnet_date_time.CopyToDateTimeString()) + + # Test year > 9999 + dotnet_date_time = dotnet_datetime.DotNetDateTime() + with self.assertRaises(ValueError): + dotnet_date_time.CopyFromDateTimeString('10000-01-01') + if __name__ == '__main__': unittest.main() diff --git a/tests/factory.py b/tests/factory.py index 8189a64..8b4a592 100644 --- a/tests/factory.py +++ b/tests/factory.py @@ -72,6 +72,9 @@ def testDateTimeValuesRegistration(self): len(factory.Factory._date_time_values_types), number_of_date_time_values_types) + with self.assertRaises(KeyError): + factory.Factory.DeregisterDateTimeValues(TestDateTimeValues) + def testNewDateTimeValues(self): """Tests the NewDateTimeValues function.""" test_date_time_values = factory.Factory.NewDateTimeValues( diff --git a/tests/golang_time.py b/tests/golang_time.py index f63102e..6c046f7 100644 --- a/tests/golang_time.py +++ b/tests/golang_time.py @@ -135,6 +135,10 @@ def testGetNumberOfSeconds(self): golang_timestamp = bytes.fromhex('ff0000000000000000000000000000') golang_time_object._GetNumberOfSeconds(golang_timestamp) + with self.assertRaises(ValueError): + golang_timestamp = bytes.fromhex('ffffffffffffffffffffffffffff01') + golang_time_object._GetNumberOfSeconds(golang_timestamp) + def testCopyFromDateTimeString(self): """Tests the CopyFromDateTimeString function.""" golang_time_object = golang_time.GolangTime() @@ -170,6 +174,9 @@ def testCopyFromDateTimeString(self): self.assertEqual(golang_time_object._nanoseconds, 567890000) self.assertEqual(golang_time_object._time_zone_offset, 60) + with self.assertRaises(ValueError): + golang_time_object.CopyFromDateTimeString('-0001-01-01') + def testCopyToDateTimeString(self): """Test the CopyToDateTimeString function.""" golang_timestamp = bytes.fromhex('010000000eafffe8d121d95050ffff') @@ -194,6 +201,10 @@ def testCopyToDateTimeString(self): date_time_string = golang_time_object.CopyToDateTimeString() self.assertEqual(date_time_string, '2000-01-01 12:23:45.000056789') + golang_time_object = golang_time.GolangTime() + date_time_string = golang_time_object.CopyToDateTimeString() + self.assertIsNone(date_time_string) + if __name__ == '__main__': unittest.main() diff --git a/tests/rfc2579_date_time.py b/tests/rfc2579_date_time.py index 93e6f6f..f8382b1 100644 --- a/tests/rfc2579_date_time.py +++ b/tests/rfc2579_date_time.py @@ -60,6 +60,10 @@ def testInitialize(self): self.assertEqual(rfc2579_date_time_object.deciseconds, 6) self.assertEqual(rfc2579_date_time_object.time_zone_offset, 120) + rfc2579_date_time_object = rfc2579_date_time.RFC2579DateTime( + rfc2579_date_time_tuple=(2010, 8, 12, 20, 6, 31, 6, '-', 2, 0)) + self.assertEqual(rfc2579_date_time_object.time_zone_offset, -120) + with self.assertRaises(ValueError): rfc2579_date_time.RFC2579DateTime( rfc2579_date_time_tuple=(2010, 8, 12, 20, 6, 31)) diff --git a/tests/serializer.py b/tests/serializer.py index fd53ce0..7d7da02 100644 --- a/tests/serializer.py +++ b/tests/serializer.py @@ -17,6 +17,27 @@ class SerializerTest(unittest.TestCase): """Tests for the date and time values serializer.""" + def testConvertDictToDateTimeValues(self): + """Test ConvertDictToDateTimeValues function.""" + json_dict = { + '__class_name__': 'PosixTime', + '__type__': 'DateTimeValues', + 'timestamp': 1281643591} + + date_time_object = serializer.Serializer.ConvertDictToDateTimeValues( + json_dict) + self.assertIsNotNone(date_time_object) + + def testConvertDateTimeValuesToDict(self): + """Test ConvertDateTimeValuesToDict function.""" + posix_time_object = posix_time.PosixTime(timestamp=1281643591) + json_dict = serializer.Serializer.ConvertDateTimeValuesToDict( + posix_time_object) + self.assertIsNotNone(json_dict) + + with self.assertRaises(TypeError): + serializer.Serializer.ConvertDateTimeValuesToDict('not a datetime') + def testConvertDateTimeValuesToJSON(self): """Test ConvertDateTimeValuesToJSON function.""" posix_time_object = posix_time.PosixTime(timestamp=1281643591) @@ -317,6 +338,11 @@ def testConvertJSONToDateTimeValues(self): json_dict) self.assertEqual(date_time_object, expected_date_time_object) + with self.assertRaises(KeyError): + json_dict = { + '__class_name__': 'UnknownType', '__type__': 'DateTimeValues'} + serializer.Serializer.ConvertJSONToDateTimeValues(json_dict) + if __name__ == '__main__': unittest.main() From e8153014fe2a9830e6478f479adbd2270f88f43a Mon Sep 17 00:00:00 2001 From: Joachim Metz Date: Wed, 13 May 2026 17:21:41 +0200 Subject: [PATCH 2/2] Worked on tests --- tests/decorators.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/decorators.py b/tests/decorators.py index 6f9dc57..0111de4 100644 --- a/tests/decorators.py +++ b/tests/decorators.py @@ -7,7 +7,7 @@ from dfdatetime import decorators -class TestClass(object): +class TestClass: """Class for testing deprecated decorator.""" def Method(self):