Example #1
0
    def test_error(self) -> None:
        """Tests the path when our_main() returns an error."""
        ctx = test_context.make_test_context()
        ctx.set_unit(test_context.TestUnit())
        argv = ["", "--mode", "stats", "--no-overpass"]
        buf = io.StringIO()

        cron.main(argv, buf, ctx)

        self.assertIn("ERROR", buf.getvalue())
Example #2
0
def main():
    print('\n'*30)
    xg = XuanGu()
    is_showtip = True
    while True:
        if is_showtip:
            showtip()
        is_showtip = True
        inp  = raw_input('>>> ').lower()
        inps = inp.split()
        if inps == []: inps = ['']
        i = inps[0]
        n = len(inps)
        if   i == '': is_showtip = False
        elif i in ['e', 'exit', '99']:      break
        elif i in ['m', 'menu', 'l', 'ls']: showtip()
        elif i in ['c', 'clear']:           print('\n'*50)
        elif i in ['1', 'jbm']:             xg.main('jbm')
        elif i in ['2', 'hlp']:             xg.main('hlp')
        elif i in ['3', 'pzr']:             xg.main('pzr')
        elif i in ['4', 'pcr']:             xg.main('pcr')
        elif i in ['5', 'tor']:             xg.main('tor')
        elif i in ['6', 'xyx']:             xg.main('xyx')
        elif i in ['9', 'zdy']:             xg.main('zdy')
        
        elif i in ['11', 'ycx']:            xg.main('ycx')
        elif i in ['12', 'sdx', 'wdx']:     xg.main('sdx')
        elif i in ['13', 'tjd', 'wvd']:     xg.main('tjd')
        elif i in ['14', 'yyx']:            xg.main('yyx')
        elif i in ['15', 'ger']:            xg.main('ger')
        
        elif i in ['21', 'all', 'a']:       xg.main('all')
        elif i in ['22', 'tra', 't']:       xg.main('tra')
        elif i in ['26', 'yxg']:            xg.main('yxg')
        elif i in ['27', 'gzg']:            xg.main('gzg')
        elif i in ['28', 'zxg']:            xg.main('zxg')
        elif i in ['29', 'ccg']:            xg.main('ccg')
        
        elif i in ['51', 'fd']:             cron.main()
        
        elif len(i) == 6:                   im.main(i)
        elif i in ['61', 'si']:             im.main()
        elif i in ['62', 'ge']:             pass
        elif i in ['66', 'se']:             xg.main('se')
        elif i in ['67', 'ud']:             xg.main('ud')
        
        elif i in ['91', 'tr']:             Trade.main()
        
        else: print('your input content is wrong, please input again!')
Example #3
0
    def test_happy(self) -> None:
        """Tests the happy path."""
        ctx = test_context.make_test_context()
        file_system = test_context.TestFileSystem()
        stats_value = io.BytesIO()
        stats_value.__setattr__("close", lambda: None)
        files = {
            ctx.get_abspath("workdir/stats/stats.json"): stats_value,
        }
        file_system.set_files(files)
        ctx.set_file_system(file_system)
        argv = ["", "--mode", "stats", "--no-overpass"]
        buf = io.StringIO()

        cron.main(argv, buf, ctx)

        # Make sure that stats.json is updated without an error.
        self.assertTrue(stats_value.tell())
        self.assertNotIn("ERROR", buf.getvalue())
Example #4
0
    def test_exception(self) -> None:
        """Tests the path when main() throws."""
        def mock_our_main(_relations: areas.Relation) -> None:
            raise Exception()

        def mock_info(_msg: str, *_args: Any, **_kwargs: Any) -> None:
            pass

        mock_error_called = False

        def mock_error(_msg: str, *_args: Any, **_kwargs: Any) -> None:
            nonlocal mock_error_called
            mock_error_called = True

        with unittest.mock.patch('util.get_abspath', get_abspath):
            with unittest.mock.patch("cron.our_main", mock_our_main):
                with unittest.mock.patch("logging.info", mock_info):
                    with unittest.mock.patch("logging.error", mock_error):
                        cron.main()

        self.assertTrue(mock_error_called)
Example #5
0
    def test_happy(self) -> None:
        """Tests the happy path."""
        mock_main_called = False

        def mock_main(_relations: areas.Relation) -> None:
            nonlocal mock_main_called
            mock_main_called = True

        mock_info_called = False

        def mock_info(_msg: str, *_args: Any, **_kwargs: Any) -> None:
            nonlocal mock_info_called
            mock_info_called = True

        with unittest.mock.patch('util.get_abspath', get_abspath):
            with unittest.mock.patch("cron.our_main", mock_main):
                with unittest.mock.patch("logging.info", mock_info):
                    cron.main()

        self.assertTrue(mock_main_called)
        self.assertTrue(mock_info_called)
Example #6
0
    def test_happy(self) -> None:
        """Tests the happy path."""
        mock_main_called = False

        def mock_main(_relations: areas.Relation, _mode: str, _update: bool, _overpass: bool) -> None:
            nonlocal mock_main_called
            mock_main_called = True

        mock_info_called = False

        def mock_info(_msg: str, *_args: Any, **_kwargs: Any) -> None:
            nonlocal mock_info_called
            mock_info_called = True

        with unittest.mock.patch("cron.our_main", mock_main):
            with unittest.mock.patch("logging.info", mock_info):
                argv = [""]
                with unittest.mock.patch('sys.argv', argv):
                    cron.main()

        self.assertTrue(mock_main_called)
        self.assertTrue(mock_info_called)
Example #7
0
import http.server
import socketserver
import os
from threading import Thread

PORT = os.environ.get("PORT") or 8000
PORT = int(PORT)

Handler = http.server.SimpleHTTPRequestHandler
httpd = socketserver.TCPServer(("", PORT), Handler)
print("serving at port", PORT)

def start_server():
    httpd.serve_forever()

t = Thread(target=start_server)
t.start()

while True:
    import cron
    import time
    cron.main()
    time.sleep(60 * 10)
    
Example #8
0
def action_runner(actions):
    main(parsed, actions)
Example #9
0
def cron():
    from cron import main
    main()