Exemplo n.º 1
0
def run_test():
    print('#1 value test : ' + Pokinator.generate())
    print('#2 value test : ' + Pokinator.generate(9))
    print('#3 value test : ' + Pokinator.generate(delimiter='*'))
    print('#4 value test : ' + Pokinator.generate(token_range=999, digit=3))

    ts = unittest.makeSuite(NameGenTest,  'test')
    runner = unittest.TextTestRunner()
    runner.run(ts)
Exemplo n.º 2
0
    def take_picture(self):
        # Configure directory path and image file name
        base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

        img_name = Pokinator.generate(generation=2, lowercase=True) + '.png'

        img_path = os.path.join(base_dir, 'saved_images', img_name)

        # Add overlay (countdown)
        img_list = ('./static/overlay_img_3.png', './static/overlay_img_2.png',
                    './static/overlay_img_1.png')
        overlay_img_list = list()

        for img in img_list:
            overlay_img_list.append(Image.open(img))

        for overlay_img in overlay_img_list:
            pad = Image.new('RGBA', (
                ((overlay_img.size[0] + 31) // 32) * 32,
                ((overlay_img.size[1] + 15) // 16) * 16,
            ))
            pad.paste(overlay_img, (0, 0))
            overlay = self.cam.add_overlay(pad.tobytes(),
                                           size=overlay_img.size,
                                           layer=3,
                                           alpha=100)
            sleep(1)
            self.cam.remove_overlay(overlay)

        # Capture the image
        self.cam.capture(img_path)
        self.cam.stop_preview()
        self.cam.led = False

        # Save image file path
        self.img = img_path

        # Read data from light sensor
        light_data = subprocess.check_output('./light/light_sensor.out')
        light_data = light_data.decode('utf-8')
        light_data = int(light_data)

        # Insert icon and datetime
        insert_datetime(img_path)
        insert_icon(img_path, light_data)

        return self.img
Exemplo n.º 3
0
 def test_generate(self):
     self.assertTrue(re.match(r'\w+-\w+-\d+', Pokinator.generate()))
Exemplo n.º 4
0
 def test_wrong_digit(self):
     with self.assertRaises(RuntimeError):
         Pokinator.generate(digit=3)
         Pokinator.generate(token_range=999, digit=4)
Exemplo n.º 5
0
 def test_wrong_delimiter(self):
     with self.assertRaises(RuntimeError):
         Pokinator.generate(delimiter=1)
Exemplo n.º 6
0
 def test_wrong_range(self):
     with self.assertRaises(RuntimeError):
         Pokinator.generate('1')
     with self.assertRaises(RuntimeError):
         Pokinator.generate(-1)
Exemplo n.º 7
0
 def test_configurable_range(self):
     self.assertTrue(re.match(r'\w+-\w+-\d$', Pokinator.generate(9)))
Exemplo n.º 8
0
 def test_not_equal_in_repeated_call(self):
     self.assertNotEqual(Pokinator.generate(), Pokinator.generate())
Exemplo n.º 9
0
 def test_wrong_generation(self):
     with self.assertRaises(RuntimeError):
         Pokinator.generate(generation=0)
     with self.assertRaises(RuntimeError):
         Pokinator.generate(generation=8)
Exemplo n.º 10
0
 def test_generate_generation(self):
     for i in range(1, 7):
         self.assertTrue(
             re.match(r'\w+-\w+-\d+', Pokinator.generate(generation=i)))
Exemplo n.º 11
0
 def test_generate_lowercase(self):
     self.assertTrue(
         re.match(r'[a-z]+-[a-z]+-\d+', Pokinator.generate(lowercase=True)))
Exemplo n.º 12
0
def poke(bot, prefix, *args):
    bot.send_message(Pokinator.generate())