@@ -791,35 +791,45 @@ def test_uri_regex_def():
791791 assert not uri_regex .findall (boilerplate % uri ), uri
792792
793793
794- def test_config (tmpdir , capsys ):
795- """
796- Tests loading options from a config file.
797- """
798- d = str (tmpdir )
799-
800- # Create sample files.
801- with open (op .join (d , 'bad.txt' ), 'w' ) as f :
794+ @pytest .mark .parametrize ('kind' , ('toml' , 'cfg' ))
795+ def test_config_toml (tmp_path , capsys , kind ):
796+ """Test loading options from a config file or toml."""
797+ d = tmp_path / 'files'
798+ d .mkdir ()
799+ with open (d / 'bad.txt' , 'w' ) as f :
802800 f .write ('abandonned donn\n ' )
803- with open (op . join ( d , 'good.txt' ) , 'w' ) as f :
801+ with open (d / 'good.txt' , 'w' ) as f :
804802 f .write ("good" )
805803
806- # Create a config file.
807- conffile = op .join (d , 'config.cfg' )
808- with open (conffile , 'w' ) as f :
809- f .write (
810- '[codespell]\n '
811- 'skip = bad.txt\n '
812- 'count = \n '
813- )
814-
815804 # Should fail when checking both.
816- code , stdout , _ = cs .main (d , count = True , std = True )
805+ code , stdout , _ = cs .main (str ( d ) , count = True , std = True )
817806 # Code in this case is not exit code, but count of misspellings.
818807 assert code == 2
819808 assert 'bad.txt' in stdout
820809
810+ if kind == 'cfg' :
811+ conffile = str (tmp_path / 'config.cfg' )
812+ args = ('--config' , conffile )
813+ with open (conffile , 'w' ) as f :
814+ f .write ("""\
815+ [codespell]
816+ skip = bad.txt, whatever.txt
817+ count =
818+ """ )
819+ else :
820+ assert kind == 'toml'
821+ pytest .importorskip ('tomli' )
822+ tomlfile = str (tmp_path / 'pyproject.toml' )
823+ args = ('--toml' , tomlfile )
824+ with open (tomlfile , 'w' ) as f :
825+ f .write ("""\
826+ [tool.codespell]
827+ skip = 'bad.txt,whatever.txt'
828+ count = false
829+ """ )
830+
821831 # Should pass when skipping bad.txt
822- code , stdout , _ = cs .main ('--config' , conffile , d , count = True , std = True )
832+ code , stdout , _ = cs .main (str ( d ), * args , count = True , std = True )
823833 assert code == 0
824834 assert 'bad.txt' not in stdout
825835
0 commit comments