@@ -886,22 +886,34 @@ def test_write(self):
886886 incar = Incar .from_file (tmp_file )
887887 assert incar == self .incar
888888
889- def test_from_str_multiline_str (self ):
889+ def test_from_str_complex (self ):
890890 r"""Test of handling complex INCAR:
891891 - Multiple statements on a single line separated by semicolon
892892 - Comments marked by hashtag # or exclamation mark !
893893 - Ignore lines does not fit (tag = values) statement format
894894 - Long lines split by backslash \
895895 - Multi-line strings (comment would not be ignored), e.g. WANNIER90_WIN
896+
897+ TODO:
898+ - test line-ending char independence
899+ - test cast casting for multi-line string (auto-capitalization?)
896900 """
897901 incar_str = r"""
902+ # Test comment handling (especially for string tags)
903+ SIGMA = 0.05 # random comment (known float tag)
904+ EDIFF = 1e-6 ! another comment (known float tag)
905+ ALGO = Normal # comment (unknown tag -> inferred as str)
906+ GGA = PE ! comment (unknown tag -> inferred as str)
907+
898908 # Test interaction between semicolon and comment
899909 ENCUT = 520; ISMEAR = 0 # smearing scheme
900910 PREC = Accurate ; LREAL = Auto ! precision and projection scheme
901- SIGMA = 0.05 # random comment with hashtag
902- EDIFF = 1e-6 ! another comment with exclamation mark
911+ NELM = 60; ! ENCUT = 200 # should not parse second assignment
912+ ENMIN = 100; # ENCUT = 200 # should not parse second assignment
903913
904- # Line continuation with backslash
914+ # Line continuation with backslash (backslash in comment)
915+ ENMAX = 200 ! \
916+ IBRION = 0 # \
905917 MAGMOM = 0 0 1.0 0 0 -1.0 \
906918 0 0 1.0 0 0 -1.0 \
907919 6*0
@@ -912,11 +924,13 @@ def test_from_str_multiline_str(self):
912924 End Projections ! random comment
913925 "
914926
915- ! invalid statement (tag = values)
927+ # Test valid statement (tag = values) in comment
916928 ! invalid ENCUT = 100
917929 # still invalid ENCUT = 200
930+
931+ # Test invalid statement (tag = values)
918932 Not a valid statement
919- ENCUT
933+ ENCUT 300
920934 """
921935
922936 incar = Incar .from_str (incar_str )
@@ -926,20 +940,32 @@ def test_from_str_multiline_str(self):
926940 "ISMEAR" ,
927941 "PREC" ,
928942 "LREAL" ,
943+ "NELM" ,
944+ "ENMIN" ,
945+ "ENMAX" ,
946+ "IBRION" ,
947+ "ALGO" ,
948+ "GGA" ,
929949 "SIGMA" ,
930950 "EDIFF" ,
931951 "MAGMOM" ,
932952 "WANNIER90_WIN" ,
933953 }
934954 assert set (incar .keys ()) == expected_keys
935955
936- # Basic parsing
956+ # Comment handling
937957 assert incar ["SIGMA" ] == approx (0.05 )
938958 assert incar ["EDIFF" ] == approx (1e-6 )
959+ assert incar ["ALGO" ] == "Normal"
960+ assert incar ["GGA" ] == "Pe"
939961
940962 # Line with both ; and comment
941963 assert incar ["ENCUT" ] == 520
942964 assert incar ["ISMEAR" ] == 0
965+ assert incar ["NELM" ] == 60
966+ assert incar ["ENMIN" ] == 100
967+ assert incar ["ENMAX" ] == 200
968+ assert incar ["IBRION" ] == 0
943969 assert incar ["PREC" ].lower () == "accurate"
944970 assert incar ["LREAL" ].lower () == "auto"
945971
@@ -953,6 +979,12 @@ def test_from_str_multiline_str(self):
953979 # Comments and structure inside string should be preserved exactly
954980 assert win .strip () == expected_win .strip ()
955981
982+ def test_from_str_not_closed_multi_line_str (self ):
983+ """Test not closed (no ending quote) multi-line string.
984+
985+ TODO:
986+ """
987+
956988 def test_get_str (self ):
957989 incar_str = self .incar .get_str (pretty = True , sort_keys = True )
958990 expected = """ALGO = Damped
@@ -1070,6 +1102,7 @@ def test_types(self):
10701102
10711103 def test_proc_types (self ):
10721104 assert Incar .proc_val ("HELLO" , "-0.85 0.85" ) == "-0.85 0.85"
1105+ # `ML_MODE` should always be lower case
10731106 assert Incar .proc_val ("ML_MODE" , "train" ) == "train"
10741107 assert Incar .proc_val ("ML_MODE" , "RUN" ) == "run"
10751108 assert Incar .proc_val ("ALGO" , "fast" ) == "Fast"
0 commit comments