-
Notifications
You must be signed in to change notification settings - Fork 3
/
test_v3.py
1748 lines (1324 loc) · 62.3 KB
/
test_v3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import pathlib
import unittest
from typing import List, Set, Optional, Tuple
import aas_core_codegen.common
from aas_core_codegen import intermediate
from aas_core_codegen.common import Identifier
from aas_core_codegen.infer_for_schema import match as infer_for_schema_match
import aas_core_meta.v3 as v3
import tests.common
class Test_matches_XML_serializable_string(unittest.TestCase):
def test_free_form_text(self) -> None:
assert v3.matches_XML_serializable_string("some free & <free> \u1984 form text")
def test_fffe(self) -> None:
assert not v3.matches_XML_serializable_string("\uFFFE")
def test_ffff(self) -> None:
assert not v3.matches_XML_serializable_string("\uFFFF")
# noinspection SpellCheckingInspection
def test_surrogate_characters(self) -> None:
assert not v3.matches_XML_serializable_string("\uD800")
assert not v3.matches_XML_serializable_string("\uDFFF")
def test_nul(self) -> None:
assert not v3.matches_XML_serializable_string("\x00")
class Test_matches_xs_date_time_utc(unittest.TestCase):
def test_empty(self) -> None:
assert not v3.matches_xs_date_time_UTC("")
def test_date(self) -> None:
assert not v3.matches_xs_date_time_UTC("2022-04-01")
def test_date_with_time_zone(self) -> None:
assert not v3.matches_xs_date_time_UTC("2022-04-01Z")
def test_date_time_without_zone(self) -> None:
assert not v3.matches_xs_date_time_UTC("2022-04-01T01:02:03")
def test_date_time_with_offset(self) -> None:
assert not v3.matches_xs_date_time_UTC("2022-04-01T01:02:03+02:00")
def test_date_time_with_UTC(self) -> None:
assert v3.matches_xs_date_time_UTC("2022-04-01T01:02:03Z")
def test_date_time_without_seconds(self) -> None:
assert not v3.matches_xs_date_time_UTC("2022-04-01T01:02Z")
def test_date_time_without_minutes(self) -> None:
assert not v3.matches_xs_date_time_UTC("2022-04-01T01Z")
def test_date_time_with_UTC_and_suffix(self) -> None:
assert not v3.matches_xs_date_time_UTC("2022-04-01T01:02:03Z-unexpected-suffix")
class Test_matches_MIME_type(unittest.TestCase):
def test_empty(self) -> None:
assert not v3.matches_MIME_type("")
def test_integer(self) -> None:
assert not v3.matches_MIME_type("1234")
def test_common(self) -> None:
assert v3.matches_MIME_type("audio/aac")
def test_dash(self) -> None:
assert v3.matches_MIME_type("application/x-abiword")
def test_dot(self) -> None:
assert v3.matches_MIME_type("application/vnd.amazon.ebook")
def test_plus(self) -> None:
assert v3.matches_MIME_type("application/vnd.apple.installer+xml")
def test_number_in_suffix(self) -> None:
assert v3.matches_MIME_type("audio/3gpp2")
class Test_matches_RFC_8089_path(unittest.TestCase):
def test_empty(self) -> None:
assert not v3.matches_RFC_8089_path("")
def test_integer(self) -> None:
assert not v3.matches_RFC_8089_path("1234")
def test_absolute_path_without_scheme(self) -> None:
assert not v3.matches_RFC_8089_path("/path/to/somewhere")
def test_relative_path_without_scheme(self) -> None:
assert not v3.matches_RFC_8089_path("path/to/somewhere")
def test_local_absolute_path_with_scheme(self) -> None:
assert v3.matches_RFC_8089_path("file:/path/to/somewhere")
def test_non_local_file_with_an_explicit_authority(self) -> None:
# See https://datatracker.ietf.org/doc/html/rfc8089#appendix-B
assert v3.matches_RFC_8089_path("file://host.example.com/path/to/file")
def test_local_relative_path_with_scheme(self) -> None:
assert not v3.matches_RFC_8089_path("file:path/to/somewhere")
class Test_matches_BCP_47(unittest.TestCase):
def test_empty(self) -> None:
assert not v3.matches_BCP_47("")
def test_free_form_text(self) -> None:
assert not v3.matches_BCP_47("some free form text")
def test_valid(self) -> None:
for text in ["de", "de-CH"]:
self.assertTrue(v3.matches_BCP_47(text), text)
class Test_matches_xs_any_URI(unittest.TestCase):
# See: http://www.datypic.com/sc/xsd/t-xsd_anyURI.html
def test_empty(self) -> None:
# NOTE (mristin, 2022-04-1):
# An empty string is a valid ``xs:anyURI``,
# see https://lists.w3.org/Archives/Public/xml-dist-app/2003Mar/0076.html and
# https://lists.w3.org/Archives/Public/xml-dist-app/2003Mar/0078.html
assert v3.matches_xs_any_URI("")
def test_integer(self) -> None:
assert v3.matches_xs_any_URI("1234")
def test_absolute_path_without_scheme(self) -> None:
assert v3.matches_xs_any_URI("/path/to/somewhere")
def test_relative_path_without_scheme(self) -> None:
assert v3.matches_xs_any_URI("path/to/somewhere")
def test_URI(self) -> None:
assert v3.matches_xs_any_URI(
"https://github.com/aas-core-works/aas-core-codegen"
)
def test_too_many_fragments(self) -> None:
assert not v3.matches_xs_any_URI("http://datypic.com#frag1#frag2")
def test_percentage_followed_by_non_two_hexadecimal_digits(self) -> None:
assert not v3.matches_xs_any_URI("http://datypic.com#f% rag")
class Test_matches_xs_base_64_binary(unittest.TestCase):
# See http://www.datypic.com/sc/xsd/t-xsd_base64Binary.html
def test_without_space_uppercase(self) -> None:
assert v3.matches_xs_base_64_binary("0FB8")
def test_without_space_lowercase(self) -> None:
assert v3.matches_xs_base_64_binary("0fb8")
def test_whitespace_is_allowed_anywhere_in_the_value(self) -> None:
assert v3.matches_xs_base_64_binary("0 FB8 0F+9")
def test_equals_signs_are_used_for_padding(self) -> None:
assert v3.matches_xs_base_64_binary("0F+40A==")
def test_an_empty_value_is_valid(self) -> None:
assert v3.matches_xs_base_64_binary("")
def test_an_odd_number_of_characters_is_not_valid(self) -> None:
# Characters must appear in groups of four.
assert not v3.matches_xs_base_64_binary("FB8")
def test_equals_signs_may_only_appear_at_the_end(self) -> None:
assert not v3.matches_xs_base_64_binary("==0F")
class Test_matches_xs_date(unittest.TestCase):
def test_empty(self) -> None:
assert not v3.matches_xs_date("")
def test_date(self) -> None:
assert v3.matches_xs_date("2022-04-01")
def test_date_with_utc(self) -> None:
assert v3.matches_xs_date("2022-04-01Z")
def test_date_with_offset(self) -> None:
assert v3.matches_xs_date("2022-04-01+02:34")
def test_date_with_invalid_offset(self) -> None:
assert not v3.matches_xs_date("2022-04-01+15:00")
def test_date_with_unexpected_suffix(self) -> None:
assert not v3.matches_xs_date("2022-04-01unexpected")
class Test_matches_xs_date_time(unittest.TestCase):
def test_empty(self) -> None:
assert not v3.matches_xs_date_time("")
def test_date(self) -> None:
assert not v3.matches_xs_date_time("2022-04-01")
def test_date_with_time_zone(self) -> None:
assert not v3.matches_xs_date_time("2022-04-01Z")
def test_date_time_without_zone(self) -> None:
assert v3.matches_xs_date_time("2022-04-01T01:02:03")
def test_date_time_with_offset(self) -> None:
assert v3.matches_xs_date_time("2022-04-01T01:02:03+02:00")
def test_date_time_with_invalid_offset(self) -> None:
assert not v3.matches_xs_date_time("2022-04-01T01:02:03+15:00")
def test_date_time_with_UTC(self) -> None:
assert v3.matches_xs_date_time("2022-04-01T01:02:03Z")
def test_date_time_without_seconds(self) -> None:
assert not v3.matches_xs_date_time("2022-04-01T01:02Z")
def test_date_time_without_minutes(self) -> None:
assert not v3.matches_xs_date_time("2022-04-01T01Z")
def test_date_time_with_unexpected_suffix(self) -> None:
assert not v3.matches_xs_date_time("2022-04-01T01:02:03Z-unexpected-suffix")
def test_date_time_with_unexpected_prefix(self) -> None:
assert not v3.matches_xs_date_time("unexpected-prefix-2022-04-01T01:02:03Z")
class Test_matches_xs_decimal(unittest.TestCase):
def test_empty(self) -> None:
assert not v3.matches_xs_decimal("")
def test_free_form_text(self) -> None:
assert not v3.matches_xs_decimal("some free form text")
def test_integer(self) -> None:
assert v3.matches_xs_decimal("1234")
def test_decimal(self) -> None:
assert v3.matches_xs_decimal("1234.01234")
def test_integer_with_preceding_zeros(self) -> None:
assert v3.matches_xs_decimal("0001234")
def test_decimal_with_preceding_zeros(self) -> None:
assert v3.matches_xs_decimal("0001234.01234")
def test_scientific_notation(self) -> None:
assert not v3.matches_xs_decimal("12.123e123")
class Test_matches_xs_double(unittest.TestCase):
def test_empty(self) -> None:
assert not v3.matches_xs_double("")
def test_free_form_text(self) -> None:
assert not v3.matches_xs_double("some free form text")
def test_integer(self) -> None:
assert v3.matches_xs_double("1234")
def test_double(self) -> None:
assert v3.matches_xs_double("1234.01234")
def test_integer_with_preceding_zeros(self) -> None:
assert v3.matches_xs_double("0001234")
def test_double_with_preceding_zeros(self) -> None:
assert v3.matches_xs_double("0001234.01234")
def test_exponent_integer(self) -> None:
assert v3.matches_xs_double("-12.34e5")
assert v3.matches_xs_double("+12.34e5")
assert v3.matches_xs_double("12.34e5")
assert v3.matches_xs_double("12.34e+5")
assert v3.matches_xs_double("12.34e-5")
def test_exponent_float(self) -> None:
assert not v3.matches_xs_double("-12.34e5.6")
assert not v3.matches_xs_double("+12.34e5.6")
assert not v3.matches_xs_double("12.34e5.6")
assert not v3.matches_xs_double("12.34e+5.6")
assert not v3.matches_xs_double("12.34e-5.6")
def test_edge_cases(self) -> None:
# NOTE (mristin, 2022-10-30):
# See: https://www.oreilly.com/library/view/xml-schema/0596002521/re67.html
assert not v3.matches_xs_double("+INF")
assert v3.matches_xs_double("-INF")
assert v3.matches_xs_double("INF")
assert v3.matches_xs_double("NaN")
def test_case_matters(self) -> None:
assert not v3.matches_xs_double("inf")
assert not v3.matches_xs_double("nan")
class Test_matches_xs_duration(unittest.TestCase):
def test_empty(self) -> None:
assert not v3.matches_xs_duration("")
def test_free_form_text(self) -> None:
assert not v3.matches_xs_duration("some free form text")
def test_integer(self) -> None:
assert not v3.matches_xs_duration("1234")
# NOTE (mristin, 2022-04-6):
# See https://www.data2type.de/xml-xslt-xslfo/xml-schema/datentypen-referenz/xs-duration
def test_valid_values(self) -> None:
for text in [
"PT1004199059S",
"PT130S",
"PT2M10S",
"P1DT2S",
"-P1Y",
"P1Y2M3DT5H20M30.123S",
]:
self.assertTrue(v3.matches_xs_duration(text), text)
def test_leading_P_missing(self) -> None:
assert not v3.matches_xs_duration("1Y")
def test_separator_T_missing(self) -> None:
assert not v3.matches_xs_duration("P1S")
def test_not_all_parts_positive(self) -> None:
assert not v3.matches_xs_duration("P-1Y")
assert not v3.matches_xs_duration("P1Y-1M")
def test_the_order_matters(self) -> None:
assert not v3.matches_xs_duration("P1M2Y")
class Test_matches_xs_float(unittest.TestCase):
def test_empty(self) -> None:
assert not v3.matches_xs_float("")
def test_free_form_text(self) -> None:
assert not v3.matches_xs_float("some free form text")
def test_integer(self) -> None:
assert v3.matches_xs_float("1234")
def test_float(self) -> None:
assert v3.matches_xs_float("1234.01234")
def test_integer_with_preceding_zeros(self) -> None:
assert v3.matches_xs_float("0001234")
def test_float_with_preceding_zeros(self) -> None:
assert v3.matches_xs_float("0001234.01234")
def test_exponent_integer(self) -> None:
assert v3.matches_xs_float("-12.34e5")
assert v3.matches_xs_float("+12.34e5")
assert v3.matches_xs_float("12.34e5")
assert v3.matches_xs_float("12.34e+5")
assert v3.matches_xs_float("12.34e-5")
def test_exponent_float(self) -> None:
assert not v3.matches_xs_float("-12.34e5.6")
assert not v3.matches_xs_float("+12.34e5.6")
assert not v3.matches_xs_float("12.34e5.6")
assert not v3.matches_xs_float("12.34e+5.6")
assert not v3.matches_xs_float("12.34e-5.6")
def test_edge_cases(self) -> None:
# NOTE (mristin, 2022-10-30):
# See: https://www.oreilly.com/library/view/xml-schema/0596002521/re67.html
assert not v3.matches_xs_float("+INF")
assert v3.matches_xs_float("-INF")
assert v3.matches_xs_float("INF")
assert v3.matches_xs_float("NaN")
def test_case_matters(self) -> None:
assert not v3.matches_xs_float("inf")
assert not v3.matches_xs_float("nan")
class Test_matches_xs_g_day(unittest.TestCase):
def test_empty(self) -> None:
assert not v3.matches_xs_g_day("")
def test_free_form_text(self) -> None:
assert not v3.matches_xs_g_day("some free form text")
# NOTE (mristin, 2022-04-6):
# See https://www.data2type.de/xml-xslt-xslfo/xml-schema/datentypen-referenz/xs-gday
def test_valid_values(self) -> None:
for text in ["---01", "---01Z", "---01+02:00", "---01-04:00", "---15", "---31"]:
self.assertTrue(v3.matches_xs_g_day(text), text)
def test_unexpected_suffix(self) -> None:
assert not v3.matches_xs_g_day("--30-")
def test_day_outside_of_range(self) -> None:
assert not v3.matches_xs_g_day("---35")
def test_missing_leading_digit(self) -> None:
assert not v3.matches_xs_g_day("---5")
def test_missing_leading_dashes(self) -> None:
assert not v3.matches_xs_g_day("15")
class Test_matches_xs_g_month(unittest.TestCase):
def test_empty(self) -> None:
assert not v3.matches_xs_g_month("")
def test_free_form_text(self) -> None:
assert not v3.matches_xs_g_month("some free form text")
# NOTE (mristin, 2022-04-6):
# See https://www.data2type.de/xml-xslt-xslfo/xml-schema/datentypen-referenz/xs-gmonth
def test_valid_values(self) -> None:
for text in ["--05", "--11Z", "--11+02:00", "--11-04:00", "--02"]:
self.assertTrue(v3.matches_xs_g_month(text), text)
def test_unexpected_prefix_and_suffix(self) -> None:
assert not v3.matches_xs_g_month("-01-")
def test_month_outside_of_range(self) -> None:
assert not v3.matches_xs_g_month("--13")
def test_missing_leading_digit(self) -> None:
assert not v3.matches_xs_g_month("--1")
def test_missing_leading_dashes(self) -> None:
assert not v3.matches_xs_g_month("01")
class Test_matches_xs_g_month_day(unittest.TestCase):
def test_empty(self) -> None:
assert not v3.matches_xs_g_month_day("")
def test_free_form_text(self) -> None:
assert not v3.matches_xs_g_month_day("some free form text")
# NOTE (mristin, 2022-04-6):
# See https://www.data2type.de/xml-xslt-xslfo/xml-schema/datentypen-referenz/xs-gmonthday
def test_valid_values(self) -> None:
for text in [
"--05-01",
"--11-01Z",
"--11-01+02:00",
"--11-01-04:00",
"--11-15",
"--02-29",
]:
self.assertTrue(v3.matches_xs_g_month_day(text), text)
def test_unexpected_prefix_and_suffix(self) -> None:
assert not v3.matches_xs_g_month_day("-01-30-")
def test_day_outside_of_range(self) -> None:
assert not v3.matches_xs_g_month_day("--01-35")
def test_missing_leading_digit(self) -> None:
assert not v3.matches_xs_g_month_day("--1-5")
def test_missing_leading_dashes(self) -> None:
assert not v3.matches_xs_g_month_day("01-15")
class Test_matches_xs_g_year(unittest.TestCase):
def test_empty(self) -> None:
assert not v3.matches_xs_g_year("")
def test_free_form_text(self) -> None:
assert not v3.matches_xs_g_year("some free form text")
# NOTE (mristin, 2022-04-6):
# See https://www.data2type.de/xml-xslt-xslfo/xml-schema/datentypen-referenz/xs-gyear
def test_valid_values(self) -> None:
for text in ["2001", "2001+02:00", "2001Z", "2001+00:00", "-2001", "-20000"]:
self.assertTrue(v3.matches_xs_g_year(text), text)
def test_missing_century(self) -> None:
assert not v3.matches_xs_g_year("01")
def test_unexpected_month(self) -> None:
assert not v3.matches_xs_g_year("2001-12")
class Test_matches_xs_g_year_month(unittest.TestCase):
def test_empty(self) -> None:
assert not v3.matches_xs_g_year_month("")
def test_free_form_text(self) -> None:
assert not v3.matches_xs_g_year_month("some free form text")
# NOTE (mristin, 2022-04-6):
# See https://www.data2type.de/xml-xslt-xslfo/xml-schema/datentypen-referenz/xs-gyearmonth
def test_valid_values(self) -> None:
for text in [
"2001-10",
"2001-10+02:00",
"2001-10Z",
"2001-10+00:00",
"-2001-10",
"-20000-04",
]:
self.assertTrue(v3.matches_xs_g_year_month(text), text)
def test_missing_month(self) -> None:
assert not v3.matches_xs_g_year_month("2001")
def test_month_out_of_range(self) -> None:
assert not v3.matches_xs_g_year_month("2001-13")
def test_missing_century(self) -> None:
assert not v3.matches_xs_g_year_month("01-13")
class Test_matches_xs_hex_binary(unittest.TestCase):
def test_empty(self) -> None:
assert v3.matches_xs_hex_binary("")
def test_free_form_text(self) -> None:
assert not v3.matches_xs_hex_binary("some free form text")
# NOTE (mristin, 2022-04-6):
# See https://www.data2type.de/xml-xslt-xslfo/xml-schema/datentypen-referenz/xs-hexbinary
def test_valid_values(self) -> None:
for text in [
"11",
"12",
"1234",
"3c3f786d6c2076657273696f6e3d22312e302220656e636f64696e67",
]:
self.assertTrue(v3.matches_xs_hex_binary(text), text)
def test_odd_number_of_digits(self) -> None:
assert not v3.matches_xs_hex_binary("1")
assert not v3.matches_xs_hex_binary("123")
class Test_matches_xs_time(unittest.TestCase):
def test_empty(self) -> None:
assert not v3.matches_xs_time("")
def test_free_form_text(self) -> None:
assert not v3.matches_xs_time("some free form text")
# NOTE (mristin, 2022-04-6):
# See https://www.data2type.de/xml-xslt-xslfo/xml-schema/datentypen-referenz/xs-time
def test_valid_values(self) -> None:
for text in [
"21:32:52",
"21:32:52+02:00",
"19:32:52Z",
"19:32:52+00:00",
"21:32:52.12679",
]:
self.assertTrue(v3.matches_xs_time(text), text)
def test_missing_seconds(self) -> None:
assert not v3.matches_xs_time("21:32")
def test_hour_out_of_range(self) -> None:
assert not v3.matches_xs_time("25:25:10")
def test_minute_out_of_range(self) -> None:
assert not v3.matches_xs_time("01:61:10")
def test_second_out_of_range(self) -> None:
assert not v3.matches_xs_time("01:02:61")
def test_negative(self) -> None:
assert not v3.matches_xs_time("-10:00:00")
def test_missing_padded_zeros(self) -> None:
assert not v3.matches_xs_time("1:20:10")
class Test_matches_xs_integer(unittest.TestCase):
def test_empty(self) -> None:
assert not v3.matches_xs_integer("")
def test_free_form_text(self) -> None:
assert not v3.matches_xs_integer("some free form text")
def test_valid_values(self) -> None:
for text in ["1", "001", "-1", "+1"]:
self.assertTrue(v3.matches_xs_integer(text), text)
def test_decimal(self) -> None:
assert not v3.matches_xs_integer("1.2")
class Test_matches_xs_long(unittest.TestCase):
def test_empty(self) -> None:
assert not v3.matches_xs_long("")
def test_free_form_text(self) -> None:
assert not v3.matches_xs_long("some free form text")
def test_valid_values(self) -> None:
for text in ["1", "001", "-1", "+1"]:
self.assertTrue(v3.matches_xs_long(text), text)
def test_decimal(self) -> None:
assert not v3.matches_xs_long("1.2")
class Test_matches_xs_int(unittest.TestCase):
def test_empty(self) -> None:
assert not v3.matches_xs_int("")
def test_free_form_text(self) -> None:
assert not v3.matches_xs_int("some free form text")
def test_valid_values(self) -> None:
for text in ["1", "001", "-1", "+1"]:
self.assertTrue(v3.matches_xs_int(text), text)
def test_decimal(self) -> None:
assert not v3.matches_xs_int("1.2")
class Test_matches_xs_short(unittest.TestCase):
def test_empty(self) -> None:
assert not v3.matches_xs_short("")
def test_free_form_text(self) -> None:
assert not v3.matches_xs_short("some free form text")
def test_valid_values(self) -> None:
for text in ["1", "001", "-1", "+1"]:
self.assertTrue(v3.matches_xs_short(text), text)
def test_decimal(self) -> None:
assert not v3.matches_xs_short("1.2")
class Test_matches_xs_byte(unittest.TestCase):
def test_empty(self) -> None:
assert not v3.matches_xs_byte("")
def test_free_form_text(self) -> None:
assert not v3.matches_xs_byte("some free form text")
def test_valid_values(self) -> None:
for text in ["1", "001", "-1", "+1"]:
self.assertTrue(v3.matches_xs_byte(text), text)
def test_decimal(self) -> None:
assert not v3.matches_xs_byte("1.2")
class Test_matches_xs_non_negative_integer(unittest.TestCase):
def test_empty(self) -> None:
assert not v3.matches_xs_non_negative_integer("")
def test_free_form_text(self) -> None:
assert not v3.matches_xs_non_negative_integer("some free form text")
def test_valid_values(self) -> None:
for text in ["-0", "1", "001", "+1", "+001"]:
self.assertTrue(v3.matches_xs_non_negative_integer(text), text)
def test_decimal(self) -> None:
assert not v3.matches_xs_non_negative_integer("1.2")
def test_negative(self) -> None:
assert not v3.matches_xs_non_negative_integer("-1")
class Test_matches_xs_positive_integer(unittest.TestCase):
def test_empty(self) -> None:
assert not v3.matches_xs_positive_integer("")
def test_free_form_text(self) -> None:
assert not v3.matches_xs_positive_integer("some free form text")
def test_valid_values(self) -> None:
for text in ["1", "001", "+1", "+001", "100"]:
self.assertTrue(v3.matches_xs_positive_integer(text), text)
def test_decimal(self) -> None:
assert not v3.matches_xs_positive_integer("1.2")
def test_negative(self) -> None:
assert not v3.matches_xs_positive_integer("-1")
def test_zero(self) -> None:
assert not v3.matches_xs_positive_integer("0")
class Test_matches_xs_unsigned_long(unittest.TestCase):
def test_empty(self) -> None:
assert not v3.matches_xs_unsigned_long("")
def test_free_form_text(self) -> None:
assert not v3.matches_xs_unsigned_long("some free form text")
def test_valid_values(self) -> None:
for text in ["-0", "1", "001", "+1", "+001"]:
self.assertTrue(v3.matches_xs_unsigned_long(text), text)
def test_decimal(self) -> None:
assert not v3.matches_xs_unsigned_long("1.2")
def test_negative(self) -> None:
assert not v3.matches_xs_unsigned_long("-1")
class Test_matches_xs_unsigned_int(unittest.TestCase):
def test_empty(self) -> None:
assert not v3.matches_xs_unsigned_int("")
def test_free_form_text(self) -> None:
assert not v3.matches_xs_unsigned_int("some free form text")
def test_valid_values(self) -> None:
for text in ["-0", "1", "001", "+1", "+001"]:
self.assertTrue(v3.matches_xs_unsigned_int(text), text)
def test_decimal(self) -> None:
assert not v3.matches_xs_unsigned_int("1.2")
def test_negative(self) -> None:
assert not v3.matches_xs_unsigned_int("-1")
class Test_matches_xs_unsigned_short(unittest.TestCase):
def test_empty(self) -> None:
assert not v3.matches_xs_unsigned_short("")
def test_free_form_text(self) -> None:
assert not v3.matches_xs_unsigned_short("some free form text")
def test_valid_values(self) -> None:
for text in ["-0", "1", "001", "+1", "+001"]:
self.assertTrue(v3.matches_xs_unsigned_short(text), text)
def test_decimal(self) -> None:
assert not v3.matches_xs_unsigned_short("1.2")
def test_negative(self) -> None:
assert not v3.matches_xs_unsigned_short("-1")
class Test_matches_xs_unsigned_byte(unittest.TestCase):
def test_empty(self) -> None:
assert not v3.matches_xs_unsigned_byte("")
def test_free_form_text(self) -> None:
assert not v3.matches_xs_unsigned_byte("some free form text")
def test_valid_values(self) -> None:
for text in ["-0", "1", "001", "+1", "+001"]:
self.assertTrue(v3.matches_xs_unsigned_byte(text), text)
def test_decimal(self) -> None:
assert not v3.matches_xs_unsigned_byte("1.2")
def test_negative(self) -> None:
assert not v3.matches_xs_unsigned_byte("-1")
class Test_matches_xs_non_positive_integer(unittest.TestCase):
def test_empty(self) -> None:
assert not v3.matches_xs_non_positive_integer("")
def test_free_form_text(self) -> None:
assert not v3.matches_xs_non_positive_integer("some free form text")
def test_valid_values(self) -> None:
for text in ["+0", "0", "-1", "-001"]:
self.assertTrue(v3.matches_xs_non_positive_integer(text), text)
def test_zero_prefixed_with_zeros(self) -> None:
assert not v3.matches_xs_non_positive_integer("000")
def test_decimal(self) -> None:
assert not v3.matches_xs_non_positive_integer("1.2")
def test_positive(self) -> None:
assert not v3.matches_xs_non_positive_integer("1")
assert not v3.matches_xs_non_positive_integer("+1")
class Test_matches_xs_negative_integer(unittest.TestCase):
def test_empty(self) -> None:
assert not v3.matches_xs_negative_integer("")
def test_free_form_text(self) -> None:
assert not v3.matches_xs_negative_integer("some free form text")
def test_valid_values(self) -> None:
for text in ["-1", "-001", "-100"]:
self.assertTrue(v3.matches_xs_negative_integer(text), text)
def test_decimal(self) -> None:
assert not v3.matches_xs_negative_integer("-1.2")
def test_zero(self) -> None:
assert not v3.matches_xs_negative_integer("0")
assert not v3.matches_xs_negative_integer("+0")
assert not v3.matches_xs_negative_integer("-0")
def test_positive(self) -> None:
assert not v3.matches_xs_negative_integer("1")
assert not v3.matches_xs_negative_integer("+1")
class Test_matches_xs_string(unittest.TestCase):
def test_empty(self) -> None:
assert v3.matches_xs_string("")
def test_free_form_text(self) -> None:
assert v3.matches_xs_string("some free & <free> \u1984 form text")
def test_fffe(self) -> None:
assert not v3.matches_xs_string("\uFFFE")
def test_ffff(self) -> None:
assert not v3.matches_xs_string("\uFFFF")
# noinspection SpellCheckingInspection
def test_surrogate_characters(self) -> None:
assert not v3.matches_xs_string("\uD800")
assert not v3.matches_xs_string("\uDFFF")
def test_nul(self) -> None:
assert not v3.matches_xs_string("\x00")
_META_MODEL: tests.common.MetaModel = tests.common.load_meta_model(
pathlib.Path(v3.__file__)
)
class Test_assertions(unittest.TestCase):
# NOTE (mristin, 2023-01-25):
# We do not state "ID" as an abbreviation (which might imply "Identity Document"),
# but rather expect "Id" or "id", short for "identifier".
#
# See: https://english.stackexchange.com/questions/101248/how-should-the-abbreviation-for-identifier-be-capitalized
LOWER_TO_ABBREVIATION = {
"aas": "AAS",
"bcp": "BCP",
"din": "DIN",
"ece": "ECE",
"html": "HTML",
"id": "ID",
"ids": "IDs",
"iec": "IEC",
"irdi": "IRDI",
"iri": "IRI",
"mime": "MIME",
"nist": "NIST",
"rfc": "RFC",
"si": "SI",
"uri": "URI",
"url": "URL",
"utc": "UTC",
"xml": "XML",
"xsd": "XSD",
}
ABBREVIATIONS = set(LOWER_TO_ABBREVIATION.values())
@staticmethod
def check_class_name(name: aas_core_codegen.common.Identifier) -> List[str]:
errors = [] # type: List[str]
parts = name.split("_") # type: List[str]
if parts[0] not in Test_assertions.ABBREVIATIONS:
if parts[0] != parts[0].capitalize():
errors.append(
f"Expected first part of a class name "
f"to be capitalized ({parts[0].capitalize()!r}), "
f"but it was not ({parts[0]!r}) for class {name!r}"
)
for part in parts:
expected_part = Test_assertions.LOWER_TO_ABBREVIATION.get(
part.lower(), None
)
if expected_part is not None and part != expected_part:
errors.append(
f"Expected a part of a class name "
f"to be {expected_part!r} "
f"since it denotes an abbreviation, "
f"but got {part!r} for the class {name!r}"
)
for part in parts[1:]:
if part not in Test_assertions.ABBREVIATIONS:
if part.lower() != part:
errors.append(
f"Expected a non-first part of a class name "
f"to be lower-case ({part.lower()}) "
f"since it was not registered as an abbreviation, "
f"but it was not ({part!r}) "
f"for class {name!r}"
)
return errors
@staticmethod
def check_enum_literal_name(name: aas_core_codegen.common.Identifier) -> List[str]:
errors = [] # type: List[str]
parts = name.split("_") # type: List[str]
if parts[0] not in Test_assertions.ABBREVIATIONS:
if parts[0] != parts[0].capitalize():
errors.append(
f"Expected first part of an enumeration literal name "
f"to be capitalized ({parts[0].capitalize()!r}), "
f"but it was not ({parts[0]!r}) for enumeration literal {name!r}"
)
for part in parts:
expected_part = Test_assertions.LOWER_TO_ABBREVIATION.get(
part.lower(), None
)
if expected_part is not None and part != expected_part:
errors.append(
f"Expected a part of an enumeration literal name "
f"to be {expected_part!r} since it denotes an abbreviation, "
f"but got {part!r} for enumeration literal {name!r}"
)
for part in parts[1:]:
if part not in Test_assertions.ABBREVIATIONS:
if part.lower() != part:
errors.append(
f"Expected a non-first part of an enumeration literal name "
f"to be lower-case ({part.lower()}) "
f"since it was not registered as an abbreviation, "
f"but it was not ({part!r}) "
f"for enumeration literal {name!r}"
)
return errors
@staticmethod
def check_property_name(name: aas_core_codegen.common.Identifier) -> List[str]:
errors = [] # type: List[str]
parts = name.split("_") # type: List[str]
for part in parts:
expected_part = Test_assertions.LOWER_TO_ABBREVIATION.get(
part.lower(), None
)
if expected_part is not None and part != expected_part:
errors.append(
f"Expected a part of a property name "
f"to be {expected_part!r} "
f"since it denotes an abbreviation, "
f"but got {part!r} for the property {name!r}"
)
for part in parts:
if part not in Test_assertions.ABBREVIATIONS:
if part.lower() != part:
errors.append(
f"Expected a part of a property name "
f"to be lower-case ({part.lower()}) "
f"since it was not registered as an abbreviation, "
f"but it was not ({part!r}) "
f"for the property {name!r}"
)
return errors
@staticmethod
def check_method_name(name: aas_core_codegen.common.Identifier) -> List[str]:
errors = [] # type: List[str]
parts = name.split("_") # type: List[str]
for part in parts:
expected_part = Test_assertions.LOWER_TO_ABBREVIATION.get(
part.lower(), None
)
if expected_part is not None and part != expected_part: