Пример #1
0
    def test_create_sketch_with_code(self):
        sketch_creator = SketchCreator()
        sketch_dir = os.getcwd()
        sketch_ino_location = os.path.join(
            sketch_dir, sketch_creator._default_sketch_name, "%s.ino" % sketch_creator._default_sketch_name
        )
        sketch_code_write = "Unicode test (ろΓαζςÂaé) on: %s" % time.strftime("%Y-%m-%d %H:%M:%S")

        sketch_return_location = sketch_creator.create_sketch(sketch_dir, sketch_code=sketch_code_write)
        self.assertEqual(sketch_return_location, sketch_ino_location)

        arduino_sketch = codecs.open(sketch_return_location, "r", encoding="utf-8")
        sketch_code_read = arduino_sketch.read()
        arduino_sketch.close()
        self.assertEqual(sketch_code_write, sketch_code_read)
Пример #2
0
    def test_create_sketch(self):
        """ Tests to see if an Arduino Sketch is created in a new location. """
        # First test with the default name
        sketch_creator = SketchCreator()
        sketch_dir = os.getcwd()
        final_ino_path = os.path.join(
            sketch_dir,
            sketch_creator._default_sketch_name,
            '%s.ino' % sketch_creator._default_sketch_name)
        # It should be save to create and delete the ino file in the test folder
        if os.path.exists(final_ino_path):
            os.remove(final_ino_path)
        self.assertFalse(os.path.isfile(final_ino_path))
        # Checks the file is saved, and saved to the right location
        created_sketch_path = sketch_creator.create_sketch(sketch_dir)
        self.assertEqual(final_ino_path, created_sketch_path)
        self.assertTrue(os.path.isfile(final_ino_path))

        # Now test with a given sketch name and a unicode path
        sketch_name = 'TestTemp_Sketch'
        sketch_dir_unicode = os.path.join(os.getcwd(), 'TestTemp_ろΓαζςÂé')
        final_ino_path = os.path.join(sketch_dir_unicode,
                                      sketch_name,
                                      sketch_name + '.ino')

        # Test directory should be a safe place to create this unicode folder
        if not os.path.exists(sketch_dir_unicode):
            os.mkdir(sketch_dir_unicode)
        else:
            # We count on this specific folder name to be too unlikely
            # created by a user and not this unit test, so remove contents
            shutil.rmtree(sketch_dir_unicode)
            os.mkdir(sketch_dir_unicode)

        self.assertFalse(os.path.isfile(final_ino_path))

        # Checks the file is saved, and saved to the right location
        created_sketch_path = sketch_creator.create_sketch(
            sketch_dir_unicode, sketch_name=sketch_name)
        self.assertEqual(final_ino_path, created_sketch_path)
        self.assertTrue(os.path.isfile(final_ino_path))

        # Remove created unicode dir
        shutil.rmtree(sketch_dir_unicode)
Пример #3
0
    def test_create_sketch_with_code(self):
        sketch_creator = SketchCreator()
        sketch_dir = os.getcwd()
        sketch_ino_location = os.path.join(
            sketch_dir,
            sketch_creator._default_sketch_name,
            '%s.ino' % sketch_creator._default_sketch_name)
        sketch_code_write = 'Unicode test (ろΓαζςÂaé) on: %s' % \
                            time.strftime("%Y-%m-%d %H:%M:%S")

        sketch_return_location = sketch_creator.create_sketch(
            sketch_dir, sketch_code=sketch_code_write)
        self.assertEqual(sketch_return_location, sketch_ino_location)

        arduino_sketch = codecs.open(
            sketch_return_location, 'r', encoding='utf-8')
        sketch_code_read = arduino_sketch.read()
        arduino_sketch.close()
        self.assertEqual(sketch_code_write, sketch_code_read)
Пример #4
0
    def test_create_sketch(self):
        """ Tests to see if an Arduino Sketch is created in a new location. """
        # First test with the default name
        sketch_creator = SketchCreator()
        sketch_dir = os.getcwd()
        final_ino_path = os.path.join(
            sketch_dir, sketch_creator._default_sketch_name, "%s.ino" % sketch_creator._default_sketch_name
        )
        # It should be save to create and delete the ino file in the test folder
        if os.path.exists(final_ino_path):
            os.remove(final_ino_path)
        self.assertFalse(os.path.isfile(final_ino_path))
        # Checks the file is saved, and saved to the right location
        created_sketch_path = sketch_creator.create_sketch(sketch_dir)
        self.assertEqual(final_ino_path, created_sketch_path)
        self.assertTrue(os.path.isfile(final_ino_path))

        # Now test with a given sketch name and a unicode path
        sketch_name = "TestTemp_Sketch"
        sketch_dir_unicode = os.path.join(os.getcwd(), "TestTemp_ろΓαζςÂé")
        final_ino_path = os.path.join(sketch_dir_unicode, sketch_name, sketch_name + ".ino")

        # Test directory should be a safe place to create this unicode folder
        if not os.path.exists(sketch_dir_unicode):
            os.mkdir(sketch_dir_unicode)
        else:
            # We count on this specific folder name to be too unlikely
            # created by a user and not this unit test, so remove contents
            shutil.rmtree(sketch_dir_unicode)
            os.mkdir(sketch_dir_unicode)

        self.assertFalse(os.path.isfile(final_ino_path))

        # Checks the file is saved, and saved to the right location
        created_sketch_path = sketch_creator.create_sketch(sketch_dir_unicode, sketch_name=sketch_name)
        self.assertEqual(final_ino_path, created_sketch_path)
        self.assertTrue(os.path.isfile(final_ino_path))

        # Remove created unicode dir
        shutil.rmtree(sketch_dir_unicode)
Пример #5
0
    def test_create_sketch_invalid(self):
        """
        Test for invalid inputs in the create_sketch method.
        """
        # Test for failure on invalid sketch path
        random_invalid_path = os.path.join(os.getcwd(), "raNd_dIr")
        self.assertFalse(os.path.isdir(random_invalid_path))
        sketch_creator = SketchCreator()
        created_sketch_path = sketch_creator.create_sketch(random_invalid_path)
        self.assertIsNone(created_sketch_path)
        self.assertFalse(os.path.isdir(random_invalid_path))

        # Test for failure on invalid sketch code
        sketch_path = os.getcwd()
        sketch_folder_path = os.path.join(sketch_path, sketch_creator._default_sketch_name)
        if os.path.isdir(sketch_folder_path):
            shutil.rmtree(sketch_folder_path)
        self.assertFalse(os.path.isdir(sketch_folder_path))
        invalid_sketch_code = True
        created_sketch_path = sketch_creator.create_sketch(sketch_path, sketch_code=invalid_sketch_code)
        self.assertIsNone(created_sketch_path)
        self.assertFalse(os.path.isdir(sketch_folder_path))
Пример #6
0
    def test_create_sketch_invalid(self):
        """
        Test for invalid inputs in the create_sketch method.
        """
        # Test for failure on invalid sketch path
        random_invalid_path = os.path.join(os.getcwd(), 'raNd_dIr')
        self.assertFalse(os.path.isdir(random_invalid_path))
        sketch_creator = SketchCreator()
        created_sketch_path = sketch_creator.create_sketch(random_invalid_path)
        self.assertIsNone(created_sketch_path)
        self.assertFalse(os.path.isdir(random_invalid_path))

        # Test for failure on invalid sketch code
        sketch_path = os.getcwd()
        sketch_folder_path = os.path.join(
            sketch_path, sketch_creator._default_sketch_name)
        if os.path.isdir(sketch_folder_path):
            shutil.rmtree(sketch_folder_path)
        self.assertFalse(os.path.isdir(sketch_folder_path))
        invalid_sketch_code = True
        created_sketch_path = sketch_creator.create_sketch(
            sketch_path, sketch_code=invalid_sketch_code)
        self.assertIsNone(created_sketch_path)
        self.assertFalse(os.path.isdir(sketch_folder_path))
Пример #7
0
def create_sketch_from_string(sketch_code):
    settings = ServerCompilerSettings()
    return SketchCreator().create_sketch(settings.sketch_dir,
                                         sketch_name=settings.sketch_name,
                                         sketch_code=sketch_code)
Пример #8
0
def create_sketch_default():
    settings = ServerCompilerSettings()
    return SketchCreator().create_sketch(settings.sketch_dir,
                                         sketch_name=settings.sketch_name)