mirror of
				https://github.com/f-droid/fdroidserver.git
				synced 2025-11-04 14:30:30 +03:00 
			
		
		
		
	
		
			
				
	
	
		
			85 lines
		
	
	
	
		
			2.2 KiB
		
	
	
	
		
			Python
		
	
	
		
			Executable file
		
	
	
	
	
			
		
		
	
	
			85 lines
		
	
	
	
		
			2.2 KiB
		
	
	
	
		
			Python
		
	
	
		
			Executable file
		
	
	
	
	
#!/usr/bin/env python3
 | 
						|
 | 
						|
import logging
 | 
						|
import optparse
 | 
						|
import os
 | 
						|
import sys
 | 
						|
import unittest
 | 
						|
import tempfile
 | 
						|
import textwrap
 | 
						|
from pathlib import Path
 | 
						|
 | 
						|
from testcommon import TmpCwd
 | 
						|
 | 
						|
localmodule = Path(__file__).resolve().parent.parent
 | 
						|
print('localmodule: ' + str(localmodule))
 | 
						|
if localmodule not in sys.path:
 | 
						|
    sys.path.insert(0, str(localmodule))
 | 
						|
 | 
						|
from fdroidserver import common
 | 
						|
from fdroidserver import rewritemeta
 | 
						|
 | 
						|
 | 
						|
class RewriteMetaTest(unittest.TestCase):
 | 
						|
    '''fdroidserver/publish.py'''
 | 
						|
 | 
						|
    def setUp(self):
 | 
						|
        logging.basicConfig(level=logging.DEBUG)
 | 
						|
        self.basedir = localmodule / 'tests'
 | 
						|
        os.chdir(self.basedir)
 | 
						|
 | 
						|
    def test_rewrite_scenario_trivial(self):
 | 
						|
        sys.argv = ['rewritemeta', 'a', 'b']
 | 
						|
 | 
						|
        with tempfile.TemporaryDirectory() as tmpdir, TmpCwd(tmpdir):
 | 
						|
            Path('metadata').mkdir()
 | 
						|
            with Path('metadata/a.yml').open('w') as f:
 | 
						|
                f.write('AutoName: a')
 | 
						|
            with Path('metadata/b.yml').open('w') as f:
 | 
						|
                f.write('AutoName: b')
 | 
						|
 | 
						|
            rewritemeta.main()
 | 
						|
 | 
						|
            self.assertEqual(
 | 
						|
                Path('metadata/a.yml').read_text(encoding='utf-8'),
 | 
						|
                textwrap.dedent(
 | 
						|
                    '''\
 | 
						|
                    License: Unknown
 | 
						|
 | 
						|
                    AutoName: a
 | 
						|
 | 
						|
                    AutoUpdateMode: None
 | 
						|
                    UpdateCheckMode: None
 | 
						|
                    '''
 | 
						|
                ),
 | 
						|
            )
 | 
						|
 | 
						|
            self.assertEqual(
 | 
						|
                Path('metadata/b.yml').read_text(encoding='utf-8'),
 | 
						|
                textwrap.dedent(
 | 
						|
                    '''\
 | 
						|
                    License: Unknown
 | 
						|
 | 
						|
                    AutoName: b
 | 
						|
 | 
						|
                    AutoUpdateMode: None
 | 
						|
                    UpdateCheckMode: None
 | 
						|
                    '''
 | 
						|
                ),
 | 
						|
            )
 | 
						|
 | 
						|
 | 
						|
if __name__ == "__main__":
 | 
						|
    parser = optparse.OptionParser()
 | 
						|
    parser.add_option(
 | 
						|
        "-v",
 | 
						|
        "--verbose",
 | 
						|
        action="store_true",
 | 
						|
        default=False,
 | 
						|
        help="Spew out even more information than normal",
 | 
						|
    )
 | 
						|
    (common.options, args) = parser.parse_args(['--verbose'])
 | 
						|
 | 
						|
    newSuite = unittest.TestSuite()
 | 
						|
    newSuite.addTest(unittest.makeSuite(RewriteMetaTest))
 | 
						|
    unittest.main(failfast=False)
 |