def test_duration(self): self.assert_supports_temporal_types() with self.driver.session() as session: result = session.run("RETURN duration('P1Y2M3DT4H5M6.789S')") value = result.single().value() self.assertIsInstance(value, duration) self.assertEqual(value, duration(1, 2, 3, 4, 5, 6.789))
def test_nanosecond_resolution_duration(self): self.assert_supports_temporal_types() with catch_warnings(record=True) as warning_list: simplefilter("always") with self.driver.session() as session: result = session.run("RETURN duration('P1Y2M3DT4H5M6.789123456S')") value = result.single().value() self.assertIsInstance(value, duration) self.assertEqual(value, duration(1, 2, 3, 4, 5, 6.789123)) self.assertEqual(len(warning_list), 1)
def test_duration(self): self.assert_supports_temporal_types() with self.driver.session() as session: result = session.run("CYPHER runtime=interpreted WITH $x AS x " "RETURN x.months, x.days, x.seconds, x.microsecondsOfSecond", x=duration(years=1, months=2, days=3, hours=4, minutes=5, seconds=6.789012)) months, days, seconds, microseconds = result.single() self.assertEqual(months, 14) self.assertEqual(days, 3) self.assertEqual(seconds, 14706) self.assertEqual(microseconds, 789012)
def test_mixed_array(self): self.assert_supports_temporal_types() with self.driver.session() as session: data = [date(1976, 6, 13), duration(9, 8, 7, 6, 5, 4)] with self.assertRaises(CypherTypeError): _ = session.write_transaction(run_and_rollback, "CREATE (a {x:$x}) RETURN a.x", x=data)
def test_duration_array(self): self.assert_supports_temporal_types() with self.driver.session() as session: data = [duration(1, 2, 3, 4, 5, 6), duration(9, 8, 7, 6, 5, 4)] value = session.write_transaction(run_and_rollback, "CREATE (a {x:$x}) RETURN a.x", x=data) self.assertEqual(value, data)