mirror of
				https://github.com/avatao-content/baseimage-tutorial-framework
				synced 2025-11-04 02:22:55 +00:00 
			
		
		
		
	Implement must_begin_similarly constraint CommandsEqual
This commit is contained in:
		@@ -7,14 +7,22 @@ from tfw.decorators.lazy_property import lazy_property
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class CommandsEqual:
 | 
					class CommandsEqual:
 | 
				
			||||||
    def __init__(self, command_1, command_2, fuzzyness=1):
 | 
					    def __init__(self, command_1, command_2, fuzzyness=1, must_begin_similarly=True):
 | 
				
			||||||
        self.command_1 = split(command_1)
 | 
					        self.command_1 = split(command_1)
 | 
				
			||||||
        self.command_2 = split(command_2)
 | 
					        self.command_2 = split(command_2)
 | 
				
			||||||
        self.fuzzyness = fuzzyness
 | 
					        self.fuzzyness = fuzzyness
 | 
				
			||||||
 | 
					        self.must_begin_similarly = must_begin_similarly
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def __bool__(self):
 | 
					    def __bool__(self):
 | 
				
			||||||
 | 
					        if self.must_begin_similarly and not self.beginnings_are_equal:
 | 
				
			||||||
 | 
					            return False
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return self.similarity >= self.fuzzyness
 | 
					        return self.similarity >= self.fuzzyness
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @lazy_property
 | 
				
			||||||
 | 
					    def beginnings_are_equal(self):
 | 
				
			||||||
 | 
					        return self.command_1[0] == self.command_2[0]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @lazy_property
 | 
					    @lazy_property
 | 
				
			||||||
    def similarity(self):
 | 
					    def similarity(self):
 | 
				
			||||||
        parts_1 = set(self.command_1)
 | 
					        parts_1 = set(self.command_1)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user