Beispiel #1
0
    def test_mkdir(self, mock_stdout):

        # test the dit has exists
        with mock.patch('main.os.path.exists', return_value=True):
            self.assertEqual(main.mkdir(BACKUP_DIR), self.path)
            main.os.path.join.assert_called_with(BASE_DIR, BACKUP_DIR, 'time')
            main.os.makedirs.assert_not_called()
            self.assertTrue(mock_stdout.getvalue() == 'doc has existed\n')

        # test the dir has not exists
        with mock.patch('main.os.path.exists', return_value=False):
            self.assertEqual(main.mkdir(BACKUP_DIR), self.path)
            main.os.makedirs.assert_called_with(self.path)
            self.assertEqual(main.os.makedirs.call_count, len(DIRNAMES) - 1)
Beispiel #2
0
 def test_mkdir_false(self):
     target = runtime + 'test_mkdir/'
     expected = False
     if not os.path.exists(target):
         os.makedirs(target)
     self.assertEqual(
         main.mkdir(target), expected, 'test [mkdir_false] fail!')
Beispiel #3
0
 def test_mkdir_true(self):
     target = runtime + 'test_mkdir/'
     expected = True
     if os.path.exists(target):
         os.removedirs(target)
     self.assertEqual(
         main.mkdir(target), expected, 'test [mkdir_true] fail!')
def handle_all_media(message):
    print("Recibiendo")
    file_id = message.json["photo"][0]["file_id"]
    file_info = bot.get_file(file_id)
    print(file_info.file_path)
    file = requests.get('https://api.telegram.org/file/bot{0}/{1}'.format(
        API_TOKEN, file_info.file_path))
    print(file)
    main.mkdir()
    if file.status_code == 200:
        with open("images/imagen.jpg", "wb") as f:
            f.write(file.content)

    if main.lengh('images/imagen.jpg') > 3:
        bot.reply_to(message,
                     "Texto: \n" + main.convertidor('images/imagen.jpg'))
    else:
        bot.reply_to(message, "No se reconoce la imagen :( \nprueba con otra.")
Beispiel #5
0
from all_albums import get_all_albums
from main import mkdir,download_pic,all_num
import time



if __name__ == '__main__':
    get_all_albums()      # 获取所有板块下所有专辑的链接,保存至txt文本
    time.sleep(1)
    mkdir()               # 创建所有板块图片的主目录
    time.sleep(1)
    download_pic()        # 开始抓取图片,目录层级自动创建
    all_num()             # 统计一共抓取了多少专辑和图片
Beispiel #6
0
        if os.path.exists(target):
            os.removedirs(target)
        self.assertEqual(
            main.mkdir(target), expected, 'test [mkdir_true] fail!')

    def test_mkdir_false(self):
        target = runtime + 'test_mkdir/'
        expected = False
        if not os.path.exists(target):
            os.makedirs(target)
        self.assertEqual(
            main.mkdir(target), expected, 'test [mkdir_false] fail!')


if __name__ == '__main__':
    main.mkdir(runtime)

    import xmlrunner

    #unittest.main(module=__name__, buffer=True, verbosity=2, exit=False)

    with open(runtime + 'test-results.xml', 'wb') as output:
        unittest.main(
            testRunner=xmlrunner.XMLTestRunner(output=output),
            module=__name__,
            buffer=True,
            verbosity=2,
            exit=False)

# vim: noai:ts=4:sw=4
Beispiel #7
0
		args.outpath = os.path.join(args.outbasepath,args.modelname,str(args.runId).zfill(2))

		args.save_dir = os.path.join(args.outpath, "save")

		args.save_dir_best = os.path.join(args.outpath, "save-best")

	if args.load_best:
		args.load = True
	if args.load_from is not None:
		args.load = True

	if args.mode == "train":
		assert args.outbasepath is not None
		assert args.modelname is not None
		args.is_train = True
		mkdir(args.save_dir)
		mkdir(args.save_dir_best)
	else:
		args.is_train = False
		args.num_epochs = 1

	args.resnet_num_block = [3, 4, 23, 3] # resnet 101
	args.use_basic_block = False
	if args.resnet152:
		args.resnet_num_block = [3, 8, 36, 3]
	if args.resnet50:
		args.resnet_num_block = [3, 4, 6, 3]
	if args.resnet34:
		args.resnet_num_block = [3, 4, 6, 3]
		args.use_basic_block = True
	if args.resnet18: